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
fix sync status
zadamf6dd1110e842
diff --git a/src/public/app/widgets/sync_status.js b/src/public/app/widgets/sync_status.jsindex 901620a05d..f8e53bfcb4 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 finishsetTimeout(() => 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.jsindex 77337ee90d..6bd7eeb48b 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.jsindex f6bca6eab4..e975f550de 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.jsindex 0fbddf4bdd..e37e06c9cb 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) {