#98, sync button now shows total number of outstanding syncs instead of just pushes

This commit is contained in:
azivner 2018-07-24 21:43:15 +02:00
parent 37ab7b4641
commit b6935abcc9
4 changed files with 13 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import utils from './utils.js'; import utils from './utils.js';
import infoService from "./info.js"; import infoService from "./info.js";
const $changesToPushCount = $("#changes-to-push-count"); const $outstandingSyncsCount = $("#outstanding-syncs-count");
const messageHandlers = []; const messageHandlers = [];
@ -43,7 +43,7 @@ function handleMessage(event) {
messageHandler(syncData); messageHandler(syncData);
} }
$changesToPushCount.html(message.changesToPushCount); $outstandingSyncsCount.html(message.outstandingSyncs);
} }
else if (message.type === 'sync-hash-check-failed') { else if (message.type === 'sync-hash-check-failed') {
infoService.showError("Sync check failed!", 60000); infoService.showError("Sync check failed!", 60000);

View File

@ -2,8 +2,6 @@ const WebSocket = require('ws');
const utils = require('./utils'); const utils = require('./utils');
const log = require('./log'); const log = require('./log');
const sql = require('./sql'); const sql = require('./sql');
const optionService = require('./options');
const syncSetup = require('./sync_setup');
let webSocketServer; let webSocketServer;
@ -65,15 +63,12 @@ async function sendMessageToAllClients(message) {
async function sendPing(client, lastSentSyncId) { async function sendPing(client, lastSentSyncId) {
const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]); const syncData = await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSentSyncId]);
const stats = require('./sync').stats;
const lastSyncedPush = await optionService.getOption('lastSyncedPush');
const changesToPushCount = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
await sendMessage(client, { await sendMessage(client, {
type: 'sync', type: 'sync',
data: syncData, data: syncData,
changesToPushCount: await syncSetup.isSyncSetup() ? changesToPushCount : 0 outstandingSyncs: stats.outstandingPushes + stats.outstandingPulls
}); });
} }

View File

@ -151,8 +151,6 @@ async function pushSync(syncContext) {
if (filteredSyncs.length === 0) { if (filteredSyncs.length === 0) {
log.info("Nothing to push"); log.info("Nothing to push");
stats.outstandingPushes = 0;
await setLastSyncedPush(lastSyncedPush); await setLastSyncedPush(lastSyncedPush);
break; break;
@ -170,8 +168,6 @@ async function pushSync(syncContext) {
lastSyncedPush = syncRecords[syncRecords.length - 1].sync.id; lastSyncedPush = syncRecords[syncRecords.length - 1].sync.id;
await setLastSyncedPush(lastSyncedPush); await setLastSyncedPush(lastSyncedPush);
stats.outstandingPushes = await sql.getValue(`SELECT MAX(id) FROM sync`) - lastSyncedPush;
} }
} }
@ -299,6 +295,12 @@ async function setLastSyncedPush(lastSyncedPush) {
await optionService.setOption('lastSyncedPush', lastSyncedPush); await optionService.setOption('lastSyncedPush', lastSyncedPush);
} }
async function updatePushStats() {
const lastSyncedPush = await optionService.getOption('lastSyncedPush');
stats.outstandingPushes = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
}
sqlInit.dbReady.then(async () => { sqlInit.dbReady.then(async () => {
if (await syncSetup.isSyncSetup()) { if (await syncSetup.isSyncSetup()) {
log.info("Setting up sync to " + await syncSetup.getSyncServer() + " with timeout " + await syncSetup.getSyncTimeout()); log.info("Setting up sync to " + await syncSetup.getSyncServer() + " with timeout " + await syncSetup.getSyncTimeout());
@ -313,6 +315,8 @@ sqlInit.dbReady.then(async () => {
// kickoff initial sync immediately // kickoff initial sync immediately
setTimeout(cls.wrap(sync), 1000); setTimeout(cls.wrap(sync), 1000);
setInterval(cls.wrap(updatePushStats), 1000);
} }
else { else {
log.info("Sync server not configured, sync timer not running.") log.info("Sync server not configured, sync timer not running.")

View File

@ -38,7 +38,7 @@
<button class="btn btn-xs" id="sync-now-button" title="Number of outstanding changes to be pushed to server"> <button class="btn btn-xs" id="sync-now-button" title="Number of outstanding changes to be pushed to server">
<span class="ui-icon ui-icon-refresh"></span> <span class="ui-icon ui-icon-refresh"></span>
Sync now (<span id="changes-to-push-count">0</span>) Sync now (<span id="outstanding-syncs-count">0</span>)
</button> </button>
<button class="btn btn-xs" id="options-button"> <button class="btn btn-xs" id="options-button">