better sync implementation of ping job

This commit is contained in:
azivner 2017-12-18 21:58:46 -05:00
parent 1b900bb907
commit 1ebf9d4e56
2 changed files with 10 additions and 11 deletions

View file

@ -1,17 +1,12 @@
const sql = require('./sql');
const utils = require('./utils');
const messaging = require('./messaging');
const options = require('./options');
const sync_setup = require('./sync_setup');
let startTime = utils.nowDate();
let sentSyncId = [];
let lastSentSyncId;
async function sendPing() {
const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ?", [startTime]);
startTime = utils.nowDate();
const syncData = syncs.filter(sync => !sentSyncId.includes(sync.id));
const syncData = await sql.getResults("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]);
const lastSyncedPush = await options.getOption('last_synced_push');
@ -23,9 +18,13 @@ async function sendPing() {
changesToPushCount: sync_setup.isSyncSetup ? changesToPushCount : 0
});
for (const sync of syncData) {
sentSyncId.push(sync.id);
if (syncData.length > 0) {
lastSentSyncId = syncData[syncData.length - 1].id;
}
}
sql.dbReady.then(() => setInterval(sendPing, 1000));
sql.dbReady.then(async () => {
lastSentSyncId = await sql.getSingleValue("SELECT MAX(id) FROM sync");
setInterval(sendPing, 1000);
});

View file

@ -280,7 +280,7 @@
</form>
</div>
<div id="sql-console-dialog" title="Event log" style="display: none; padding: 20px;">
<div id="sql-console-dialog" title="SQL console" style="display: none; padding: 20px;">
<textarea style="width: 100%; height: 100px" id="sql-console-query"></textarea>
<button class="btn btn-danger" id="sql-console-execute">Execute</button>