removed outstandingPushes counting which is not needed

This commit is contained in:
zadam 2020-11-18 22:30:00 +01:00
parent fd6b2f1e7f
commit a346ba7038
6 changed files with 14 additions and 34 deletions

View File

@ -8,8 +8,6 @@ import options from "./options.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
import noteAttributeCache from "./note_attribute_cache.js"; import noteAttributeCache from "./note_attribute_cache.js";
const $outstandingSyncsCount = $("#outstanding-syncs-count");
const messageHandlers = []; const messageHandlers = [];
let ws; let ws;
@ -64,8 +62,6 @@ async function handleMessage(event) {
let syncRows = message.data; let syncRows = message.data;
lastPingTs = Date.now(); lastPingTs = Date.now();
$outstandingSyncsCount.html(message.outstandingSyncs);
if (syncRows.length > 0) { if (syncRows.length > 0) {
logRows(syncRows); logRows(syncRows);

View File

@ -130,7 +130,7 @@ function SetupModel() {
} }
async function checkOutstandingSyncs() { async function checkOutstandingSyncs() {
const { stats, initialized } = await $.get('api/sync/stats'); const { outstandingPullCount, initialized } = await $.get('api/sync/stats');
if (initialized) { if (initialized) {
if (utils.isElectron()) { if (utils.isElectron()) {
@ -143,9 +143,7 @@ async function checkOutstandingSyncs() {
} }
} }
else { else {
const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls; $("#outstanding-syncs").html(outstandingPullCount);
$("#outstanding-syncs").html(totalOutstandingSyncs);
} }
} }

View File

@ -41,7 +41,7 @@ const TPL = `
<a class="dropdown-item sync-now-button" title="Trigger sync"> <a class="dropdown-item sync-now-button" title="Trigger sync">
<span class="bx bx-refresh"></span> <span class="bx bx-refresh"></span>
Sync now (<span id="outstanding-syncs-count">0</span>) Sync now
</a> </a>
<a class="dropdown-item" data-trigger-command="openNewWindow"> <a class="dropdown-item" data-trigger-command="openNewWindow">

View File

@ -43,7 +43,7 @@ function getStats() {
const stats = { const stats = {
initialized: optionService.getOption('initialized') === 'true', initialized: optionService.getOption('initialized') === 'true',
stats: syncService.stats outstandingPullCount: syncService.getOutstandingPullCount()
}; };
log.info(`Returning sync stats: ${JSON.stringify(stats)}`); log.info(`Returning sync stats: ${JSON.stringify(stats)}`);

View File

@ -20,10 +20,7 @@ const entityConstructor = require('../entities/entity_constructor');
let proxyToggle = true; let proxyToggle = true;
const stats = { let outstandingPullCount = 0;
outstandingPushes: 0,
outstandingPulls: 0
};
async function sync() { async function sync() {
try { try {
@ -135,11 +132,7 @@ async function pullChanges(syncContext) {
const pulledDate = Date.now(); const pulledDate = Date.now();
stats.outstandingPulls = resp.maxEntityChangeId - lastSyncedPull; outstandingPullCount = Math.max(0, resp.maxEntityChangeId - lastSyncedPull);
if (stats.outstandingPulls < 0) {
stats.outstandingPulls = 0;
}
const {entityChanges} = resp; const {entityChanges} = resp;
@ -159,13 +152,13 @@ async function pullChanges(syncContext) {
syncUpdateService.updateEntity(entityChange, entity, syncContext.sourceId); 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); 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) { if (atLeastOnePullApplied) {
@ -359,31 +352,25 @@ function setLastSyncedPush(entityChangeId) {
optionService.setOption('lastSyncedPush', 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() { function getMaxEntityChangeId() {
return sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes'); return sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes');
} }
function getOutstandingPullCount() {
return outstandingPullCount;
}
sqlInit.dbReady.then(() => { sqlInit.dbReady.then(() => {
setInterval(cls.wrap(sync), 60000); setInterval(cls.wrap(sync), 60000);
// kickoff initial sync immediately // kickoff initial sync immediately
setTimeout(cls.wrap(sync), 3000); setTimeout(cls.wrap(sync), 3000);
setInterval(cls.wrap(updatePushStats), 1000);
}); });
module.exports = { module.exports = {
sync, sync,
login, login,
getEntityChangesRecords, getEntityChangesRecords,
stats, getOutstandingPullCount,
getMaxEntityChangeId getMaxEntityChangeId
}; };

View File

@ -110,8 +110,7 @@ function sendPing(client, syncRows = []) {
sendMessage(client, { sendMessage(client, {
type: 'sync', type: 'sync',
data: syncRows, data: syncRows
outstandingSyncs: stats.outstandingPushes + stats.outstandingPulls
}); });
} }