diff --git a/db/migrations/0173__isErased_in_entity_changes.sql b/db/migrations/0173__isErased_in_entity_changes.sql index b2dada076..5125ddcfb 100644 --- a/db/migrations/0173__isErased_in_entity_changes.sql +++ b/db/migrations/0173__isErased_in_entity_changes.sql @@ -11,32 +11,32 @@ CREATE TABLE IF NOT EXISTS "mig_entity_changes" ( INSERT INTO mig_entity_changes (id, entityName, entityId, hash, sourceId, isSynced, utcDateChanged, isErased) SELECT id, entityName, entityId, '', sourceId, isSynced, utcChangedDate, 0 FROM entity_changes; -UPDATE mig_entity_changes SET isErased = (SELECT isErased FROM notes WHERE noteId = entityId) WHERE entityName = 'notes'; +UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'notes'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM notes WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'notes'; -UPDATE mig_entity_changes SET isErased = (SELECT isErased FROM notes WHERE noteId = entityId) WHERE entityName = 'note_contents'; +UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'note_contents'; -UPDATE mig_entity_changes SET isErased = ( +UPDATE mig_entity_changes SET isErased = COALESCE(( SELECT isErased FROM attributes JOIN notes USING(noteId) WHERE attributeId = entityId -) WHERE entityName = 'attributes'; +), 0) WHERE entityName = 'attributes'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM attributes WHERE attributeId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'attributes'; -UPDATE mig_entity_changes SET isErased = ( +UPDATE mig_entity_changes SET isErased = COALESCE(( SELECT isErased FROM branches JOIN notes USING(noteId) WHERE branchId = entityId -) WHERE entityName = 'branches'; +), 0) WHERE entityName = 'branches'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM branches WHERE branchId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'branches'; -UPDATE mig_entity_changes SET isErased = ( +UPDATE mig_entity_changes SET isErased = COALESCE(( SELECT isErased FROM note_revisions WHERE noteRevisionId = entityId -) WHERE entityName = 'note_revisions'; +), 0) WHERE entityName = 'note_revisions'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_revisions WHERE noteRevisionId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_revisions'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateCreated FROM api_tokens WHERE apiTokenId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'api_tokens'; diff --git a/src/public/app/services/link_map.js b/src/public/app/services/link_map.js index 0972a13e7..f34b34c34 100644 --- a/src/public/app/services/link_map.js +++ b/src/public/app/services/link_map.js @@ -65,7 +65,7 @@ export default class LinkMap { await froca.getNotes(Array.from(noteIds)); - // pre-fetch the link titles, it's important to have hte construction afterwards synchronous + // pre-fetch the link titles, it's important to have the construction afterwards synchronous // since jsPlumb caculates width of the element const $linkTitles = {}; diff --git a/src/public/app/widgets/sync_status.js b/src/public/app/widgets/sync_status.js index 0aaa28bc5..f8e53bfcb 100644 --- a/src/public/app/widgets/sync_status.js +++ b/src/public/app/widgets/sync_status.js @@ -3,7 +3,6 @@ import toastService from "../services/toast.js"; import ws from "../services/ws.js"; import options from "../services/options.js"; import syncService from "../services/sync.js"; -import appContext from "../services/app_context.js"; const TPL = `
@@ -108,7 +107,7 @@ export default class SyncStatusWidget extends BasicWidget { showIcon(className) { if (!options.get('syncServerHost')) { - this.$widget.hide(); + this.toggleInt(false); return; } @@ -127,29 +126,31 @@ 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; } - if (this.syncState === 'unknown') { - this.showIcon('unknown'); + this.allChangesPushed = this.lastSyncedPush === ws.getMaxKnownEntityChangeSyncId(); + + if (['unknown', 'in-progress'].includes(this.syncState)) { + this.showIcon(this.syncState); } else { this.showIcon(this.syncState + '-' + (this.allChangesPushed ? 'no-changes' : 'with-changes')); } diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 909c45790..b2aa33412 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -111,8 +111,6 @@ function forceNoteSync(req) { entityChangesService.moveEntityChangeToTop('note_revision_contents', noteRevisionId); } - entityChangesService.moveEntityChangeToTop('recent_changes', noteId); - log.info("Forcing note sync for " + noteId); // not awaiting for the job to finish (will probably take a long time) diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 92c2e441c..6bd7eeb48 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -48,9 +48,11 @@ function addNoteReorderingEntityChange(parentNoteId, sourceId) { } function moveEntityChangeToTop(entityName, entityId) { - const [hash, isSynced] = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]); + const ec = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]); - addEntityChange(entityName, entityId, hash, null, 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 7833603d9..edb64ce9b 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 15c4cb750..c0c110012 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -131,19 +131,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) {