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
removed outstandingPushes counting which is not needed
zadama346ba7038d9
diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.jsindex afcff6216e..243570b1ad 100644--- a/src/public/app/services/ws.js+++ b/src/public/app/services/ws.js@@ -8,8 +8,6 @@ import options from "./options.js";import treeCache from "./tree_cache.js";import noteAttributeCache from "./note_attribute_cache.js";-const $outstandingSyncsCount = $("#outstanding-syncs-count");-const messageHandlers = [];let ws;@@ -64,8 +62,6 @@ async function handleMessage(event) {let syncRows = message.data;lastPingTs = Date.now();- $outstandingSyncsCount.html(message.outstandingSyncs);-if (syncRows.length > 0) {logRows(syncRows);diff --git a/src/public/app/setup.js b/src/public/app/setup.jsindex 602a6fc7ef..1c792deba7 100644--- a/src/public/app/setup.js+++ b/src/public/app/setup.js@@ -130,7 +130,7 @@ function SetupModel() {}async function checkOutstandingSyncs() {- const { stats, initialized } = await $.get('api/sync/stats');+ const { outstandingPullCount, initialized } = await $.get('api/sync/stats');if (initialized) {if (utils.isElectron()) {@@ -143,9 +143,7 @@ async function checkOutstandingSyncs() {}}else {- const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls;-- $("#outstanding-syncs").html(totalOutstandingSyncs);+ $("#outstanding-syncs").html(outstandingPullCount);}}diff --git a/src/public/app/widgets/global_menu.js b/src/public/app/widgets/global_menu.jsindex ea0c0bde8c..3fc0dbfbea 100644--- a/src/public/app/widgets/global_menu.js+++ b/src/public/app/widgets/global_menu.js@@ -41,7 +41,7 @@ const TPL = `<a class="dropdown-item sync-now-button" title="Trigger sync"><span class="bx bx-refresh"></span>- Sync now (<span id="outstanding-syncs-count">0</span>)+ Sync now</a><a class="dropdown-item" data-trigger-command="openNewWindow">diff --git a/src/routes/api/sync.js b/src/routes/api/sync.jsindex b0d1da20f6..5cbbda945d 100644--- a/src/routes/api/sync.js+++ b/src/routes/api/sync.js@@ -43,7 +43,7 @@ function getStats() {const stats = {initialized: optionService.getOption('initialized') === 'true',- stats: syncService.stats+ outstandingPullCount: syncService.getOutstandingPullCount()};log.info(`Returning sync stats: ${JSON.stringify(stats)}`);diff --git a/src/services/sync.js b/src/services/sync.jsindex 30976a5e46..2e6bb06f7d 100644--- a/src/services/sync.js+++ b/src/services/sync.js@@ -20,10 +20,7 @@ const entityConstructor = require('../entities/entity_constructor');let proxyToggle = true;-const stats = {- outstandingPushes: 0,- outstandingPulls: 0-};+let outstandingPullCount = 0;async function sync() {try {@@ -135,11 +132,7 @@ async function pullChanges(syncContext) {const pulledDate = Date.now();- stats.outstandingPulls = resp.maxEntityChangeId - lastSyncedPull;-- if (stats.outstandingPulls < 0) {- stats.outstandingPulls = 0;- }+ outstandingPullCount = Math.max(0, resp.maxEntityChangeId - lastSyncedPull);const {entityChanges} = resp;@@ -159,13 +152,13 @@ async function pullChanges(syncContext) {syncUpdateService.updateEntity(entityChange, entity, syncContext.sourceId);}- stats.outstandingPulls = resp.maxEntityChangeId - entityChange.id;+ outstandingPullCount = Math.max(0, resp.maxEntityChangeId - entityChange.id);}setLastSyncedPull(entityChanges[entityChanges.length - 1].entityChange.id);});- log.info(`Pulled ${entityChanges.length} changes starting at entityChangeId=${lastSyncedPull} in ${pulledDate - startDate}ms and applied them in ${Date.now() - pulledDate}ms, ${stats.outstandingPulls} outstanding pulls`);+ log.info(`Pulled ${entityChanges.length} changes starting at entityChangeId=${lastSyncedPull} in ${pulledDate - startDate}ms and applied them in ${Date.now() - pulledDate}ms, ${outstandingPullCount} outstanding pulls`);}if (atLeastOnePullApplied) {@@ -359,31 +352,25 @@ function setLastSyncedPush(entityChangeId) {optionService.setOption('lastSyncedPush', entityChangeId);}-function updatePushStats() {- if (syncOptions.isSyncSetup()) {- const lastSyncedPush = optionService.getOption('lastSyncedPush');-- stats.outstandingPushes = sql.getValue("SELECT COUNT(1) FROM entity_changes WHERE isSynced = 1 AND id > ?", [lastSyncedPush]);- }-}-function getMaxEntityChangeId() {return sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes');}+function getOutstandingPullCount() {+ return outstandingPullCount;+}+sqlInit.dbReady.then(() => {setInterval(cls.wrap(sync), 60000);// kickoff initial sync immediatelysetTimeout(cls.wrap(sync), 3000);-- setInterval(cls.wrap(updatePushStats), 1000);});module.exports = {sync,login,getEntityChangesRecords,- stats,+ getOutstandingPullCount,getMaxEntityChangeId};diff --git a/src/services/ws.js b/src/services/ws.jsindex 400932d311..320a5e6f95 100644--- a/src/services/ws.js+++ b/src/services/ws.js@@ -110,8 +110,7 @@ function sendPing(client, syncRows = []) {sendMessage(client, {type: 'sync',- data: syncRows,- outstandingSyncs: stats.outstandingPushes + stats.outstandingPulls+ data: syncRows});}