From 2030c8e99569d5fa6a7b034b6879c0ac725380a0 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 14 May 2021 21:52:14 +0200 Subject: [PATCH 1/5] fallback value for isErased for 0173 migration, #1937 --- .../0173__isErased_in_entity_changes.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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'; From cecce1df2062e7498bed88a1e4e641cbb46ac540 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 14 May 2021 22:23:11 +0200 Subject: [PATCH 2/5] electron upgrade --- package-lock.json | 12 ++++++------ package.json | 2 +- src/public/app/services/link_map.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7096059e6..2de07a769 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2797,9 +2797,9 @@ } }, "electron": { - "version": "13.0.0-beta.23", - "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.23.tgz", - "integrity": "sha512-JGHwQRTqzMsvG0/nxTPpKov999rE5kfYryYve1tKBfXvtyMWAcNlkYh2/u5eWZXcyYWVljq3i0sN+U1IQgx+Rw==", + "version": "13.0.0-beta.26", + "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.26.tgz", + "integrity": "sha512-glDAQjSzV26JvmB9pbdd1dLkjqUvBv9X0B8FrRvIK0BAhEmMzzZ3gKD6VPsxg2omDYMI35oThQ+92D4RxRcb+g==", "dev": true, "requires": { "@electron/get": "^1.0.1", @@ -2808,9 +2808,9 @@ }, "dependencies": { "@types/node": { - "version": "14.14.44", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.44.tgz", - "integrity": "sha512-+gaugz6Oce6ZInfI/tK4Pq5wIIkJMEJUu92RB3Eu93mtj4wjjjz9EB5mLp5s1pSsLXdC/CPut/xF20ZzAQJbTA==", + "version": "14.14.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.45.tgz", + "integrity": "sha512-DssMqTV9UnnoxDWu959sDLZzfvqCF0qDNRjaWeYSui9xkFe61kKo4l1TWNTQONpuXEm+gLMRvdlzvNHBamzmEw==", "dev": true } } diff --git a/package.json b/package.json index 5a616df81..3033a8ab1 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ }, "devDependencies": { "cross-env": "7.0.3", - "electron": "13.0.0-beta.23", + "electron": "13.0.0-beta.26", "electron-builder": "22.11.1", "electron-packager": "15.2.0", "electron-rebuild": "2.3.5", diff --git a/src/public/app/services/link_map.js b/src/public/app/services/link_map.js index ec696cc15..72dc7a16b 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 treeCache.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 = {}; From 4ff40ba14f6637bcd8522c0ff571e33367037f45 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 15 May 2021 13:44:12 +0200 Subject: [PATCH 3/5] fix sync status in-progress --- src/public/app/widgets/sync_status.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/public/app/widgets/sync_status.js b/src/public/app/widgets/sync_status.js index 0aaa28bc5..901620a05 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; } @@ -148,8 +147,8 @@ export default class SyncStatusWidget extends BasicWidget { this.allChangesPushed = lastSyncedPush === ws.getMaxKnownEntityChangeSyncId(); } - if (this.syncState === 'unknown') { - this.showIcon('unknown'); + if (['unknown', 'in-progress'].includes(this.syncState)) { + this.showIcon(this.syncState); } else { this.showIcon(this.syncState + '-' + (this.allChangesPushed ? 'no-changes' : 'with-changes')); } From 623200b92bb6f5d1f7b4d4ed7c4608e4c6ec8ef6 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 15 May 2021 14:04:01 +0200 Subject: [PATCH 4/5] fix "force note sync" --- src/routes/api/sync.js | 2 -- src/services/entity_changes.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 43bbdb656..728d13cb0 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..77337ee90 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -48,9 +48,9 @@ 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); + insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced); } function addEntityChangesForSector(entityName, sector) { From f6dd1110e842a8b84f2bbdaadad315763045c152 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 15 May 2021 22:00:53 +0200 Subject: [PATCH 5/5] fix sync status --- src/public/app/widgets/sync_status.js | 12 +++++++----- src/services/entity_changes.js | 4 +++- src/services/sync.js | 7 +++++-- src/services/ws.js | 8 ++++---- 4 files changed, 19 insertions(+), 12 deletions(-) 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) {