diff --git a/package-lock.json b/package-lock.json index 0723c7057..f408c38bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1232,7 +1232,7 @@ "dependencies": { "file-type": { "version": "3.9.0", - "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" } } @@ -1508,7 +1508,7 @@ }, "uuid": { "version": "2.0.3", - "resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", "integrity": "sha1-Z+LoY3lyFVMN/zGOW/nc6/1Hsho=" } } @@ -1542,7 +1542,7 @@ "dependencies": { "semver": { "version": "4.3.6", - "resolved": "http://registry.npmjs.org/semver/-/semver-4.3.6.tgz", + "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz", "integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto=" } } @@ -1562,7 +1562,7 @@ }, "bl": { "version": "1.2.2", - "resolved": "http://registry.npmjs.org/bl/-/bl-1.2.2.tgz", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", "requires": { "readable-stream": "^2.3.5", @@ -1822,12 +1822,12 @@ "dependencies": { "file-type": { "version": "3.9.0", - "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" }, "uuid": { "version": "2.0.3", - "resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", "integrity": "sha1-Z+LoY3lyFVMN/zGOW/nc6/1Hsho=" } } @@ -1942,7 +1942,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "requires": { "core-util-is": "~1.0.0", @@ -2117,7 +2117,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "requires": { "ansi-styles": "^2.2.1", @@ -2434,7 +2434,7 @@ }, "commander": { "version": "2.8.1", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.8.1.tgz", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz", "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=", "requires": { "graceful-readlink": ">= 1.0.0" @@ -3099,7 +3099,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "requires": { "core-util-is": "~1.0.0", @@ -3316,9 +3316,9 @@ } }, "electron": { - "version": "9.0.0-beta.24", - "resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0-beta.24.tgz", - "integrity": "sha512-25L3XMqm/1CCaV5CgU5ZkhKXw9830WeipJrTW0+VC5XTKp/3xHwhxyQ5G1kQnOTJd7IGwOamvw237D6e1YKnng==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0.tgz", + "integrity": "sha512-JsaSQNPh+XDYkLj8APtVKTtvpb86KIG57W5OOss4TNrn8L3isC9LsCITwfnVmGIXHhvX6oY/weCtN5hAAytjVg==", "dev": true, "requires": { "@electron/get": "^1.0.1", @@ -4928,7 +4928,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "getpass": { @@ -5192,7 +5192,7 @@ }, "got": { "version": "5.7.1", - "resolved": "http://registry.npmjs.org/got/-/got-5.7.1.tgz", + "resolved": "https://registry.npmjs.org/got/-/got-5.7.1.tgz", "integrity": "sha1-X4FjWmHkplifGAVp6k44FoClHzU=", "requires": { "create-error-class": "^3.0.1", @@ -5840,7 +5840,7 @@ }, "into-stream": { "version": "3.1.0", - "resolved": "http://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz", + "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz", "integrity": "sha1-lvsKk2wSur1v8XUqF9BWFqvQlMY=", "requires": { "from2": "^2.1.1", @@ -5992,7 +5992,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=" }, "is-object": { @@ -6626,7 +6626,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "requires": { "graceful-fs": "^4.1.2", @@ -7135,7 +7135,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "minipass": { @@ -7235,7 +7235,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" @@ -7243,7 +7243,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" } } @@ -7437,7 +7437,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "got": { @@ -7473,7 +7473,7 @@ }, "p-cancelable": { "version": "0.4.1", - "resolved": "http://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz", "integrity": "sha512-HNa1A8LvB1kie7cERyy21VNeHb2CWJJYqyyC2o3klWFfMGlFmWv2Z7sFgZH8ZiaYL95ydToKTFVXgMV/Os0bBQ==" }, "p-event": { @@ -7597,7 +7597,7 @@ "dependencies": { "file-type": { "version": "3.9.0", - "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" } } @@ -7622,7 +7622,7 @@ "dependencies": { "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "pify": { @@ -7679,7 +7679,7 @@ }, "get-stream": { "version": "2.3.1", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", "integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=", "requires": { "object-assign": "^4.0.1", @@ -7709,7 +7709,7 @@ "dependencies": { "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" } } @@ -7749,7 +7749,7 @@ }, "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" }, "prepend-http": { @@ -7854,7 +7854,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "requires": { "core-util-is": "~1.0.0", @@ -8232,7 +8232,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=" }, "open": { @@ -8384,7 +8384,7 @@ }, "p-is-promise": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=" }, "p-limit": { @@ -8865,7 +8865,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" } } @@ -9149,7 +9149,7 @@ "dependencies": { "file-type": { "version": "3.9.0", - "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" } } @@ -9174,7 +9174,7 @@ "dependencies": { "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "pify": { @@ -9212,7 +9212,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" } } @@ -9264,7 +9264,7 @@ }, "get-stream": { "version": "2.3.1", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", "integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=", "requires": { "object-assign": "^4.0.1", @@ -9294,7 +9294,7 @@ "dependencies": { "get-stream": { "version": "3.0.0", - "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" } } @@ -9482,7 +9482,7 @@ }, "query-string": { "version": "5.1.1", - "resolved": "http://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz", "integrity": "sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==", "requires": { "decode-uri-component": "^0.2.0", @@ -9621,7 +9621,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -10489,7 +10489,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "requires": { "ansi-regex": "^2.0.0" @@ -10514,7 +10514,7 @@ }, "strip-dirs": { "version": "1.1.1", - "resolved": "http://registry.npmjs.org/strip-dirs/-/strip-dirs-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/strip-dirs/-/strip-dirs-1.1.1.tgz", "integrity": "sha1-lgu9EoeETzl1pFWKoQOoJV4kVqA=", "requires": { "chalk": "^1.0.0", @@ -10772,7 +10772,7 @@ }, "through": { "version": "2.3.8", - "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "through2": { @@ -10791,7 +10791,7 @@ }, "readable-stream": { "version": "1.0.34", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", "requires": { "core-util-is": "~1.0.0", diff --git a/package.json b/package.json index d9aaaff44..df0b1c810 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "yazl": "^2.5.1" }, "devDependencies": { - "electron": "9.0.0-beta.24", + "electron": "9.0.0", "electron-builder": "22.6.0", "electron-packager": "14.2.1", "electron-rebuild": "1.11.0", diff --git a/src/public/app/services/load_results.js b/src/public/app/services/load_results.js index ddd174a24..89965e8f3 100644 --- a/src/public/app/services/load_results.js +++ b/src/public/app/services/load_results.js @@ -4,7 +4,7 @@ export default class LoadResults { this.noteIdToSourceId = {}; this.sourceIdToNoteIds = {}; - + this.branches = []; this.attributes = []; @@ -103,10 +103,10 @@ export default class LoadResults { /** * @return {boolean} true if there are changes which could affect the attributes (including inherited ones) + * notably changes in note itself should not have any effect on attributes */ hasAttributeRelatedChanges() { - return Object.keys(this.noteIdToSourceId).length === 0 - && this.branches.length === 0 + return this.branches.length === 0 && this.attributes.length === 0; } @@ -119,4 +119,4 @@ export default class LoadResults { && this.contentNoteIdToSourceId.length === 0 && this.options.length === 0; } -} \ No newline at end of file +} diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js index f7fa956a2..736cab6ea 100644 --- a/src/public/app/services/tree.js +++ b/src/public/app/services/tree.js @@ -162,6 +162,13 @@ function getNoteIdFromNotePath(notePath) { } function getNoteIdAndParentIdFromNotePath(notePath) { + if (notePath === 'root') { + return { + noteId: 'root', + parentNoteId: 'none' + }; + } + let parentNoteId = 'root'; let noteId = ''; diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js index 6c4e6e160..3ddb70bc9 100644 --- a/src/public/app/services/ws.js +++ b/src/public/app/services/ws.js @@ -39,7 +39,18 @@ let consumeQueuePromise = null; // most sync events are sent twice - once immediatelly after finishing the transaction and once during the scheduled ping // but we want to process only once -const receivedSyncIds = new Set(); +const processedSyncIds = new Set(); + +function logRows(syncRows) { + const filteredRows = syncRows.filter(row => + !processedSyncIds.has(row.id) + && row.entityName !== 'recent_notes' + && (row.entityName !== 'options' || row.entityId !== 'openTabs')); + + if (filteredRows.length > 0) { + console.debug(utils.now(), "Sync data: ", filteredRows); + } +} async function handleMessage(event) { const message = JSON.parse(event.data); @@ -55,20 +66,9 @@ async function handleMessage(event) { $outstandingSyncsCount.html(message.outstandingSyncs); if (syncRows.length > 0) { - const filteredRows = syncRows.filter(row => - !receivedSyncIds.has(row.id) - && row.entityName !== 'recent_notes' - && (row.entityName !== 'options' || row.entityId !== 'openTabs')); + logRows(syncRows); - if (filteredRows.length > 0) { - console.debug(utils.now(), "Sync data: ", filteredRows); - } - - for (const row of filteredRows) { - receivedSyncIds.add(row.id); - } - - syncDataQueue.push(...filteredRows); + syncDataQueue.push(...syncRows); // we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates lastAcceptedSyncId = Math.max(lastAcceptedSyncId, syncRows[syncRows.length - 1].id); @@ -142,13 +142,21 @@ async function runSafely(syncHandler, syncData) { } } +/** + * TODO: we should rethink the fact that each sync row is sent twice (once at the end of transaction, once periodically) + * and we keep both lastProcessedSyncId and processedSyncIds + * it even seems incorrect that when transaction sync rows are received, we incorrectly increase lastProcessedSyncId + * and then some syncs might lost (or are *all* sync rows sent from transactions?) + */ async function consumeSyncData() { if (syncDataQueue.length > 0) { - const allSyncData = syncDataQueue; + const allSyncRows = syncDataQueue; syncDataQueue = []; + const nonProcessedSyncRows = allSyncRows.filter(sync => !processedSyncIds.has(sync.id)); + try { - await processSyncRows(allSyncData); + await processSyncRows(nonProcessedSyncRows); } catch (e) { logError(`Encountered error ${e.message}: ${e.stack}, reloading frontend.`); @@ -157,7 +165,7 @@ async function consumeSyncData() { utils.reloadApp(); } - lastProcessedSyncId = Math.max(lastProcessedSyncId, allSyncData[allSyncData.length - 1].id); + lastProcessedSyncId = Math.max(lastProcessedSyncId, allSyncRows[allSyncRows.length - 1].id); } checkSyncIdListeners(); @@ -221,18 +229,18 @@ subscribeToMessages(message => { async function processSyncRows(syncRows) { const missingNoteIds = []; - syncRows.forEach(({entityName, entity}) => { - if (entityName === 'branches' && !(entity.parentNoteId in treeCache.notes)) { + for (const {entityName, entity} of syncRows) { + if (entityName === 'branches' && !(entity.parentNoteId in treeCache.notes)) { missingNoteIds.push(entity.parentNoteId); - } - else if (entityName === 'attributes' - && entity.type === 'relation' - && entity.name === 'template' - && !(entity.noteId in treeCache.notes)) { + } + else if (entityName === 'attributes' + && entity.type === 'relation' + && entity.name === 'template' + && !(entity.noteId in treeCache.notes)) { - missingNoteIds.push(entity.value); - } - }); + missingNoteIds.push(entity.value); + } + } if (missingNoteIds.length > 0) { await treeCache.reloadNotes(missingNoteIds); @@ -240,16 +248,16 @@ async function processSyncRows(syncRows) { const loadResults = new LoadResults(treeCache); - syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'notes')) { const note = treeCache.notes[sync.entityId]; if (note) { note.update(sync.entity); loadResults.addNote(sync.entityId, sync.sourceId); } - }); + } - syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'branches')) { let branch = treeCache.branches[sync.entityId]; const childNote = treeCache.notes[sync.entity.noteId]; const parentNote = treeCache.notes[sync.entity.parentNoteId]; @@ -295,9 +303,9 @@ async function processSyncRows(syncRows) { } } } - }); + } - syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'note_reordering')) { for (const branchId in sync.positions) { const branch = treeCache.branches[branchId]; @@ -307,10 +315,10 @@ async function processSyncRows(syncRows) { } loadResults.addNoteReordering(sync.entityId, sync.sourceId); - }); + } // missing reloading the relation target note - syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'attributes')) { let attribute = treeCache.attributes[sync.entityId]; const sourceNote = treeCache.notes[sync.entity.noteId]; const targetNote = sync.entity.type === 'relation' && treeCache.notes[sync.entity.value]; @@ -346,27 +354,27 @@ async function processSyncRows(syncRows) { } } } - }); + } - syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'note_contents')) { delete treeCache.noteComplementPromises[sync.entityId]; loadResults.addNoteContent(sync.entityId, sync.sourceId); - }); + } - syncRows.filter(sync => sync.entityName === 'note_revisions').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'note_revisions')) { loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId); - }); + } - syncRows.filter(sync => sync.entityName === 'options').forEach(sync => { + for (const sync of syncRows.filter(sync => sync.entityName === 'options')) { if (sync.entity.name === 'openTabs') { - return; // only noise + continue; // only noise } options.set(sync.entity.name, sync.entity.value); loadResults.addOption(sync.entity.name); - }); + } if (!loadResults.isEmpty()) { if (loadResults.hasAttributeRelatedChanges()) { diff --git a/src/public/app/services/zoom.js b/src/public/app/services/zoom.js index ad7faa08b..d5b4b4eb6 100644 --- a/src/public/app/services/zoom.js +++ b/src/public/app/services/zoom.js @@ -9,9 +9,11 @@ class ZoomService extends Component { constructor() { super(); - options.initializedPromise.then(() => { - this.setZoomFactor(options.getFloat('zoomFactor')); - }); + if (utils.isElectron()) { + options.initializedPromise.then(() => { + this.setZoomFactor(options.getFloat('zoomFactor')); + }); + } } setZoomFactor(zoomFactor) { diff --git a/src/public/app/widgets/component.js b/src/public/app/widgets/component.js index 9ca210248..4e042c559 100644 --- a/src/public/app/widgets/component.js +++ b/src/public/app/widgets/component.js @@ -82,6 +82,10 @@ export default class Component { let release; try { + if (this.mutex.isLocked()) { + console.debug("Mutex locked for", this.constructor.name); + } + release = await this.mutex.acquire(); await fun.call(this, data); @@ -93,4 +97,4 @@ export default class Component { } } } -} \ No newline at end of file +} diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 6b690f13c..1fca3ae91 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -308,9 +308,10 @@ export default class NoteDetailWidget extends TabAwareWidget { return; } - await noteCreateService.createNote(note.noteId, { + // without await as this otherwise causes deadlock through component mutex + noteCreateService.createNote(note.noteId, { isProtected: note.isProtected, saveSelection: true }); } -} \ No newline at end of file +} diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 7464c793a..109b9bb7b 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -11,6 +11,14 @@ async function exportBranch(req, res) { const {branchId, type, format, version, taskId} = req.params; const branch = await repository.getBranch(branchId); + if (!branch) { + const message = `Cannot export branch ${branchId} since it does not exist.`; + log.error(message); + + res.status(500).send(message); + return; + } + const taskContext = new TaskContext(taskId, 'export'); try { @@ -39,4 +47,4 @@ async function exportBranch(req, res) { module.exports = { exportBranch -}; \ No newline at end of file +};