diff --git a/services/ping_job.js b/services/ping_job.js index 2faaf87ab..c9666ae77 100644 --- a/services/ping_job.js +++ b/services/ping_job.js @@ -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)); \ No newline at end of file +sql.dbReady.then(async () => { + lastSentSyncId = await sql.getSingleValue("SELECT MAX(id) FROM sync"); + + setInterval(sendPing, 1000); +}); \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 2e807e7a5..e249db3f0 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -280,7 +280,7 @@ -