From a346ba7038d9119cef9836ff42dc23e0bd201857 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 18 Nov 2020 22:30:00 +0100 Subject: [PATCH] removed outstandingPushes counting which is not needed --- src/public/app/services/ws.js | 4 ---- src/public/app/setup.js | 6 ++---- src/public/app/widgets/global_menu.js | 2 +- src/routes/api/sync.js | 2 +- src/services/sync.js | 31 ++++++++------------------- src/services/ws.js | 3 +-- 6 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js index afcff6216..243570b1a 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.js index 602a6fc7e..1c792deba 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.js index ea0c0bde8..3fc0dbfbe 100644 --- a/src/public/app/widgets/global_menu.js +++ b/src/public/app/widgets/global_menu.js @@ -41,7 +41,7 @@ const TPL = ` - Sync now (0) + Sync now diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index b0d1da20f..5cbbda945 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.js index 30976a5e4..2e6bb06f7 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 immediately setTimeout(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.js index 400932d31..320a5e6f9 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 }); }