diff --git a/package-lock.json b/package-lock.json index 56f5893fa..3c4253fc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3255,9 +3255,9 @@ } }, "electron-rebuild": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.9.0.tgz", - "integrity": "sha512-lnHW+gJIhukqVhME2v+LRDldafWwP0kGOPEpPuj59+F4NHEfu/vOjk8OLBcgDGt72CSWZm7zFUDE07oZxQJbHw==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.10.0.tgz", + "integrity": "sha512-n10i30GJg7JH8yZL3ZY3x80YtKmSYuuN8cl+3Feljm+sQDU4rUW1jbnYGu0eUHlK3kPOiNWPtW7srGcwZ9p1zQ==", "dev": true, "requires": { "colors": "^1.3.3", @@ -3268,7 +3268,7 @@ "node-gyp": "^6.0.1", "ora": "^3.4.0", "spawn-rx": "^3.0.0", - "yargs": "^13.2.4" + "yargs": "^14.2.0" }, "dependencies": { "rxjs": { @@ -5236,6 +5236,11 @@ "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=" }, + "is-docker": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.0.0.tgz", + "integrity": "sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ==" + }, "is-dotfile": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz", @@ -5731,6 +5736,11 @@ "graceful-fs": "^4.1.9" } }, + "kruptein": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/kruptein/-/kruptein-2.0.5.tgz", + "integrity": "sha512-1WRXAil8d5jZ6jNXC0/pOC2lJsu2GhL3zhzL7DDvtCsef+NC1JvZUXnyNnM6Kuv0aan54moM/hsPvUAkx3y7/w==" + }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -7258,11 +7268,12 @@ "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=" }, "open": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/open/-/open-7.0.0.tgz", - "integrity": "sha512-K6EKzYqnwQzk+/dzJAQSBORub3xlBTxMz+ntpZpH/LyCa1o6KjXhuN+2npAaI9jaSmU3R1Q8NWf4KUWcyytGsQ==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/open/-/open-7.0.1.tgz", + "integrity": "sha512-/fVm742AZt6bZ3NpbmBzGpZksDiGbo+xz8RylegKSAnTCgT5u5tvJe0cre3QxICphqHhJHc0OFtFyvU7rNx8+Q==", "requires": { - "is-wsl": "^2.1.0" + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" } }, "optionator": { @@ -9124,12 +9135,13 @@ } }, "session-file-store": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/session-file-store/-/session-file-store-1.3.1.tgz", - "integrity": "sha512-6W8N+ziXDoT3oNKqLP+38QMO1CELfWHhn7/G/T/Bj2BXLKnkJCCFqWIb9E50Rr3ENtzuxy3FT9KHy39+skBubg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/session-file-store/-/session-file-store-1.4.0.tgz", + "integrity": "sha512-jBeQwoHoHMOBoELxf+f/IDtMI94PqkFrwCP6O3DlvJlsCU6gY6pgWJGxUOtLWxauIdvAqmgoAbpJi7vJih9bvA==", "requires": { "bagpipe": "^0.3.5", "fs-extra": "^8.0.1", + "kruptein": "^2.0.4", "object-assign": "^4.1.1", "retry": "^0.12.0", "write-file-atomic": "1.3.1" @@ -10576,12 +10588,13 @@ "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" }, "yargs": { - "version": "13.3.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", - "integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", + "version": "14.2.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.2.tgz", + "integrity": "sha512-/4ld+4VV5RnrynMhPZJ/ZpOCGSCeghMykZ3BhdFBDa9Wy/RH6uEGNWDJog+aUlq+9OM1CFTgtYRW5Is1Po9NOA==", "dev": true, "requires": { "cliui": "^5.0.0", + "decamelize": "^1.2.0", "find-up": "^3.0.0", "get-caller-file": "^2.0.1", "require-directory": "^2.1.1", @@ -10590,7 +10603,7 @@ "string-width": "^3.0.0", "which-module": "^2.0.0", "y18n": "^4.0.0", - "yargs-parser": "^13.1.1" + "yargs-parser": "^15.0.0" }, "dependencies": { "ansi-regex": { @@ -10641,9 +10654,9 @@ } }, "yargs-parser": { - "version": "13.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", - "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.0.tgz", + "integrity": "sha512-xLTUnCMc4JhxrPEPUYD5IBR1mWCK/aT6+RJ/K29JY2y1vD+FhtgKK0AXRWvI262q3QSffAQuTouFIKUuHX89wQ==", "dev": true, "requires": { "camelcase": "^5.0.0", diff --git a/package.json b/package.json index 9cfe11523..45191c5bc 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mime-types": "2.1.26", "multer": "1.4.2", "node-abi": "2.13.0", - "open": "7.0.0", + "open": "7.0.1", "pngjs": "3.4.0", "portscanner": "2.2.0", "rand-token": "0.4.0", @@ -64,7 +64,7 @@ "sax": "1.2.4", "semver": "7.1.1", "serve-favicon": "2.5.0", - "session-file-store": "1.3.1", + "session-file-store": "1.4.0", "simple-node-logger": "18.12.24", "sqlite": "3.0.3", "sqlite3": "4.1.1", @@ -79,7 +79,7 @@ "electron": "6.0.12", "electron-builder": "22.3.2", "electron-packager": "14.2.0", - "electron-rebuild": "1.9.0", + "electron-rebuild": "1.10.0", "jsdoc": "3.6.3", "lorem-ipsum": "2.0.3" }, diff --git a/src/public/javascripts/services/load_results.js b/src/public/javascripts/services/load_results.js index 4d9506ad9..9ce1c5a51 100644 --- a/src/public/javascripts/services/load_results.js +++ b/src/public/javascripts/services/load_results.js @@ -1,14 +1,16 @@ export class LoadResults { constructor() { - this.noteIdToSync = {}; + this.noteIdToSourceId = {}; this.sourceIdToNoteIds = {}; + + this.branchIdToSourceId = {}; } addNote(noteId, sourceId) { - this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || []; + this.noteIdToSourceId[noteId] = this.noteIdToSourceId[noteId] || []; - if (!this.noteIdToSync[noteId].includes(sourceId)) { - this.noteIdToSync[noteId].push(sourceId); + if (!this.noteIdToSourceId[noteId].includes(sourceId)) { + this.noteIdToSourceId[noteId].push(sourceId); } this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[sourceId] || []; @@ -18,8 +20,21 @@ export class LoadResults { } } + addBranch(branchId, sourceId) { + this.branchIdToSourceId[branchId] = this.branchIdToSourceId[branchId] || []; + this.branchIdToSourceId[branchId].push(sourceId); + } + + addNoteReordering(parentNoteId, sourceId) { + + } + + addAttribute(attributeId, sourceId) { + + } + getNoteIds() { - return Object.keys(this.noteIdToSync); + return Object.keys(this.noteIdToSourceId); } isNoteReloaded(noteId, sourceId) { @@ -27,7 +42,7 @@ export class LoadResults { return false; } - const sourceIds = this.noteIdToSync[noteId]; + const sourceIds = this.noteIdToSourceId[noteId]; return sourceIds && !!sourceIds.find(sId => sId !== sourceId); } } \ No newline at end of file diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js index dddaf19eb..b08ab56f5 100644 --- a/src/public/javascripts/services/tree_cache.js +++ b/src/public/javascripts/services/tree_cache.js @@ -129,6 +129,8 @@ class TreeCache { return; } + noteIds = Array.from(new Set(noteIds)); // make noteIds unique + const resp = await server.post('tree/load', { noteIds }); this.addResp(resp.notes, resp.branches, resp.attributes); @@ -229,31 +231,40 @@ class TreeCache { } async processSyncRows(syncRows) { + const noteIdsToReload = []; + const loadResults = new LoadResults(); syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => { - const branch = this.branches[sync.entityId]; - // we assume that the cache contains the old branch state and we add also the old parentNoteId - // so that the old parent can also be updated - loadResults.addNote(branch.parentNoteId, sync.sourceId); + noteIdsToReload.push(sync.parentNoteId); + noteIdsToReload.push(sync.noteId); - // this should then contain new parentNoteId for which we should also update the cache - loadResults.addNote(sync.parentNoteId, sync.sourceId); - - loadResults.addNote(sync.noteId, sync.sourceId); + loadResults.addBranch(sync.entityId, sync.sourceId); }); - syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId)); + syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => { + noteIdsToReload.push(sync.entityId); - syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.addNote(sync.entityId, sync.sourceId)); + loadResults.addNote(sync.entityId, sync.sourceId); + }); + + syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => { + noteIdsToReload.push(sync.entityId); + + loadResults.addNoteReordering(sync.entityId, sync.sourceId); + }); // missing reloading the relation target note - syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.addNote(sync.noteId, sync.sourceId)); + syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => { + noteIdsToReload.push(sync.noteId); - await this.reloadNotes(loadResults.getNoteIds()); + loadResults.addAttribute(sync.entityId, sync.sourceId); + }); + + await this.reloadNotes(noteIdsToReload); const appContext = (await import('./app_context.js')).default; - appContext.trigger('notesReloaded', {loadResults}); + appContext.trigger('entitiesReloaded', {loadResults}); } } diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 7b8c78fba..d5bfad04f 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -220,8 +220,8 @@ export default class NoteDetailWidget extends TabAwareWidget { this.refresh(); } - notesReloadedListener(data) { - super.notesReloadedListener(data); + entitiesReloadedListener(data) { + super.entitiesReloadedListener(data); return false; // stop propagation to children } diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 8bb3ee6e3..73abac935 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -427,7 +427,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } } - async notesReloadedListener({loadResults}) { + async entitiesReloadedListener({loadResults}) { const activeNode = this.getActiveNode(); const activateNotePath = activeNode ? await treeService.getNotePath(activeNode) : null; @@ -511,7 +511,7 @@ export default class NoteTreeWidget extends TabAwareWidget { // activateNotePath = appContext.getActiveTabNotePath(); // } // - // appContext.trigger('notesReloaded', { noteIds, activateNotePath }); + // appContext.trigger('entitiesReloaded', { noteIds, activateNotePath }); // } async reloadTreeListener() { diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js index e259718b3..2d261bba3 100644 --- a/src/public/javascripts/widgets/tab_aware_widget.js +++ b/src/public/javascripts/widgets/tab_aware_widget.js @@ -60,7 +60,7 @@ export default class TabAwareWidget extends BasicWidget { this.activeTabChanged(); } - notesReloadedListener({loadResults}) { + entitiesReloadedListener({loadResults}) { if (loadResults.isNoteReloaded(this.noteId, this.componentId)) { this.refreshWithNote(this.note, this.notePath); }