diff --git a/src/public/app/widgets/sync_status.js b/src/public/app/widgets/sync_status.js index 901620a05..f8e53bfcb 100644 --- a/src/public/app/widgets/sync_status.js +++ b/src/public/app/widgets/sync_status.js @@ -126,27 +126,29 @@ export default class SyncStatusWidget extends BasicWidget { }); this.syncState = 'in-progress'; - this.allChangesPushed = false; + this.lastSyncedPush = message.lastSyncedPush; } else if (message.type === 'sync-push-in-progress') { this.syncState = 'in-progress'; - this.allChangesPushed = false; + this.lastSyncedPush = message.lastSyncedPush; } else if (message.type === 'sync-finished') { // this gives user a chance to see the toast in case of fast sync finish setTimeout(() => toastService.closePersistent('sync'), 1000); this.syncState = 'connected'; + this.lastSyncedPush = message.lastSyncedPush; } else if (message.type === 'sync-failed') { this.syncState = 'disconnected'; + this.lastSyncedPush = message.lastSyncedPush; } else if (message.type === 'frontend-update') { - const {lastSyncedPush} = message.data; - - this.allChangesPushed = lastSyncedPush === ws.getMaxKnownEntityChangeSyncId(); + this.lastSyncedPush = message.data.lastSyncedPush; } + this.allChangesPushed = this.lastSyncedPush === ws.getMaxKnownEntityChangeSyncId(); + if (['unknown', 'in-progress'].includes(this.syncState)) { this.showIcon(this.syncState); } else { diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 77337ee90..6bd7eeb48 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -50,7 +50,9 @@ function addNoteReorderingEntityChange(parentNoteId, sourceId) { function moveEntityChangeToTop(entityName, entityId) { const ec = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]); - insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced); + const localEntityChange = insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced); + + cls.addEntityChange(localEntityChange); } function addEntityChangesForSector(entityName, sector) { diff --git a/src/services/sync.js b/src/services/sync.js index f6bca6eab..e975f550d 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -334,6 +334,7 @@ function getEntityChangesRecords(entityChanges) { const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId); if (entityChange.entityName === 'options' && !entity.isSynced) { + // if non-synced entities should count towards "lastSyncedPush" records.push({entityChange}); continue; @@ -358,7 +359,8 @@ function getLastSyncedPull() { } function setLastSyncedPull(entityChangeId) { - optionService.setOption('lastSyncedPull', entityChangeId); + // this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes + sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPull']); } function getLastSyncedPush() { @@ -372,7 +374,8 @@ function getLastSyncedPush() { function setLastSyncedPush(entityChangeId) { ws.setLastSyncedPush(entityChangeId); - optionService.setOption('lastSyncedPush', entityChangeId); + // this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes + sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']); } function getMaxEntityChangeId() { diff --git a/src/services/ws.js b/src/services/ws.js index 0fbddf4bd..e37e06c9c 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -127,19 +127,19 @@ function sendTransactionEntityChangesToAllClients() { } function syncPullInProgress() { - sendMessageToAllClients({ type: 'sync-pull-in-progress' }); + sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush }); } function syncPushInProgress() { - sendMessageToAllClients({ type: 'sync-push-in-progress' }); + sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush }); } function syncFinished() { - sendMessageToAllClients({ type: 'sync-finished' }); + sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush }); } function syncFailed() { - sendMessageToAllClients({ type: 'sync-failed' }); + sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush }); } function setLastSyncedPush(entityChangeId) {