Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
better sync implementation of ping job
azivner1ebf9d4e560e
diff --git a/services/ping_job.js b/services/ping_job.jsindex 2faaf87abf..c9666ae77b 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 filediff --git a/views/index.ejs b/views/index.ejsindex 2e807e7a57..e249db3f05 100644--- a/views/index.ejs+++ b/views/index.ejs@@ -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>