refactored entity reloading

This commit is contained in:
zadam 2020-01-29 20:14:02 +01:00
parent 976b2aa6f5
commit 439b45b0b8
7 changed files with 84 additions and 45 deletions

49
package-lock.json generated
View File

@ -3255,9 +3255,9 @@
} }
}, },
"electron-rebuild": { "electron-rebuild": {
"version": "1.9.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.9.0.tgz", "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.10.0.tgz",
"integrity": "sha512-lnHW+gJIhukqVhME2v+LRDldafWwP0kGOPEpPuj59+F4NHEfu/vOjk8OLBcgDGt72CSWZm7zFUDE07oZxQJbHw==", "integrity": "sha512-n10i30GJg7JH8yZL3ZY3x80YtKmSYuuN8cl+3Feljm+sQDU4rUW1jbnYGu0eUHlK3kPOiNWPtW7srGcwZ9p1zQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"colors": "^1.3.3", "colors": "^1.3.3",
@ -3268,7 +3268,7 @@
"node-gyp": "^6.0.1", "node-gyp": "^6.0.1",
"ora": "^3.4.0", "ora": "^3.4.0",
"spawn-rx": "^3.0.0", "spawn-rx": "^3.0.0",
"yargs": "^13.2.4" "yargs": "^14.2.0"
}, },
"dependencies": { "dependencies": {
"rxjs": { "rxjs": {
@ -5236,6 +5236,11 @@
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz",
"integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=" "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": { "is-dotfile": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz", "resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz",
@ -5731,6 +5736,11 @@
"graceful-fs": "^4.1.9" "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": { "latest-version": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz",
@ -7258,11 +7268,12 @@
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=" "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
}, },
"open": { "open": {
"version": "7.0.0", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/open/-/open-7.0.0.tgz", "resolved": "https://registry.npmjs.org/open/-/open-7.0.1.tgz",
"integrity": "sha512-K6EKzYqnwQzk+/dzJAQSBORub3xlBTxMz+ntpZpH/LyCa1o6KjXhuN+2npAaI9jaSmU3R1Q8NWf4KUWcyytGsQ==", "integrity": "sha512-/fVm742AZt6bZ3NpbmBzGpZksDiGbo+xz8RylegKSAnTCgT5u5tvJe0cre3QxICphqHhJHc0OFtFyvU7rNx8+Q==",
"requires": { "requires": {
"is-wsl": "^2.1.0" "is-docker": "^2.0.0",
"is-wsl": "^2.1.1"
} }
}, },
"optionator": { "optionator": {
@ -9124,12 +9135,13 @@
} }
}, },
"session-file-store": { "session-file-store": {
"version": "1.3.1", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/session-file-store/-/session-file-store-1.3.1.tgz", "resolved": "https://registry.npmjs.org/session-file-store/-/session-file-store-1.4.0.tgz",
"integrity": "sha512-6W8N+ziXDoT3oNKqLP+38QMO1CELfWHhn7/G/T/Bj2BXLKnkJCCFqWIb9E50Rr3ENtzuxy3FT9KHy39+skBubg==", "integrity": "sha512-jBeQwoHoHMOBoELxf+f/IDtMI94PqkFrwCP6O3DlvJlsCU6gY6pgWJGxUOtLWxauIdvAqmgoAbpJi7vJih9bvA==",
"requires": { "requires": {
"bagpipe": "^0.3.5", "bagpipe": "^0.3.5",
"fs-extra": "^8.0.1", "fs-extra": "^8.0.1",
"kruptein": "^2.0.4",
"object-assign": "^4.1.1", "object-assign": "^4.1.1",
"retry": "^0.12.0", "retry": "^0.12.0",
"write-file-atomic": "1.3.1" "write-file-atomic": "1.3.1"
@ -10576,12 +10588,13 @@
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
}, },
"yargs": { "yargs": {
"version": "13.3.0", "version": "14.2.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.2.tgz",
"integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", "integrity": "sha512-/4ld+4VV5RnrynMhPZJ/ZpOCGSCeghMykZ3BhdFBDa9Wy/RH6uEGNWDJog+aUlq+9OM1CFTgtYRW5Is1Po9NOA==",
"dev": true, "dev": true,
"requires": { "requires": {
"cliui": "^5.0.0", "cliui": "^5.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0", "find-up": "^3.0.0",
"get-caller-file": "^2.0.1", "get-caller-file": "^2.0.1",
"require-directory": "^2.1.1", "require-directory": "^2.1.1",
@ -10590,7 +10603,7 @@
"string-width": "^3.0.0", "string-width": "^3.0.0",
"which-module": "^2.0.0", "which-module": "^2.0.0",
"y18n": "^4.0.0", "y18n": "^4.0.0",
"yargs-parser": "^13.1.1" "yargs-parser": "^15.0.0"
}, },
"dependencies": { "dependencies": {
"ansi-regex": { "ansi-regex": {
@ -10641,9 +10654,9 @@
} }
}, },
"yargs-parser": { "yargs-parser": {
"version": "13.1.1", "version": "15.0.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.0.tgz",
"integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", "integrity": "sha512-xLTUnCMc4JhxrPEPUYD5IBR1mWCK/aT6+RJ/K29JY2y1vD+FhtgKK0AXRWvI262q3QSffAQuTouFIKUuHX89wQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"camelcase": "^5.0.0", "camelcase": "^5.0.0",

View File

@ -54,7 +54,7 @@
"mime-types": "2.1.26", "mime-types": "2.1.26",
"multer": "1.4.2", "multer": "1.4.2",
"node-abi": "2.13.0", "node-abi": "2.13.0",
"open": "7.0.0", "open": "7.0.1",
"pngjs": "3.4.0", "pngjs": "3.4.0",
"portscanner": "2.2.0", "portscanner": "2.2.0",
"rand-token": "0.4.0", "rand-token": "0.4.0",
@ -64,7 +64,7 @@
"sax": "1.2.4", "sax": "1.2.4",
"semver": "7.1.1", "semver": "7.1.1",
"serve-favicon": "2.5.0", "serve-favicon": "2.5.0",
"session-file-store": "1.3.1", "session-file-store": "1.4.0",
"simple-node-logger": "18.12.24", "simple-node-logger": "18.12.24",
"sqlite": "3.0.3", "sqlite": "3.0.3",
"sqlite3": "4.1.1", "sqlite3": "4.1.1",
@ -79,7 +79,7 @@
"electron": "6.0.12", "electron": "6.0.12",
"electron-builder": "22.3.2", "electron-builder": "22.3.2",
"electron-packager": "14.2.0", "electron-packager": "14.2.0",
"electron-rebuild": "1.9.0", "electron-rebuild": "1.10.0",
"jsdoc": "3.6.3", "jsdoc": "3.6.3",
"lorem-ipsum": "2.0.3" "lorem-ipsum": "2.0.3"
}, },

View File

@ -1,14 +1,16 @@
export class LoadResults { export class LoadResults {
constructor() { constructor() {
this.noteIdToSync = {}; this.noteIdToSourceId = {};
this.sourceIdToNoteIds = {}; this.sourceIdToNoteIds = {};
this.branchIdToSourceId = {};
} }
addNote(noteId, sourceId) { addNote(noteId, sourceId) {
this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || []; this.noteIdToSourceId[noteId] = this.noteIdToSourceId[noteId] || [];
if (!this.noteIdToSync[noteId].includes(sourceId)) { if (!this.noteIdToSourceId[noteId].includes(sourceId)) {
this.noteIdToSync[noteId].push(sourceId); this.noteIdToSourceId[noteId].push(sourceId);
} }
this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[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() { getNoteIds() {
return Object.keys(this.noteIdToSync); return Object.keys(this.noteIdToSourceId);
} }
isNoteReloaded(noteId, sourceId) { isNoteReloaded(noteId, sourceId) {
@ -27,7 +42,7 @@ export class LoadResults {
return false; return false;
} }
const sourceIds = this.noteIdToSync[noteId]; const sourceIds = this.noteIdToSourceId[noteId];
return sourceIds && !!sourceIds.find(sId => sId !== sourceId); return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
} }
} }

View File

@ -129,6 +129,8 @@ class TreeCache {
return; return;
} }
noteIds = Array.from(new Set(noteIds)); // make noteIds unique
const resp = await server.post('tree/load', { noteIds }); const resp = await server.post('tree/load', { noteIds });
this.addResp(resp.notes, resp.branches, resp.attributes); this.addResp(resp.notes, resp.branches, resp.attributes);
@ -229,31 +231,40 @@ class TreeCache {
} }
async processSyncRows(syncRows) { async processSyncRows(syncRows) {
const noteIdsToReload = [];
const loadResults = new LoadResults(); const loadResults = new LoadResults();
syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => { syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
const branch = this.branches[sync.entityId]; noteIdsToReload.push(sync.parentNoteId);
// we assume that the cache contains the old branch state and we add also the old parentNoteId noteIdsToReload.push(sync.noteId);
// so that the old parent can also be updated
loadResults.addNote(branch.parentNoteId, sync.sourceId);
// this should then contain new parentNoteId for which we should also update the cache loadResults.addBranch(sync.entityId, sync.sourceId);
loadResults.addNote(sync.parentNoteId, sync.sourceId);
loadResults.addNote(sync.noteId, 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 // 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; const appContext = (await import('./app_context.js')).default;
appContext.trigger('notesReloaded', {loadResults}); appContext.trigger('entitiesReloaded', {loadResults});
} }
} }

View File

@ -220,8 +220,8 @@ export default class NoteDetailWidget extends TabAwareWidget {
this.refresh(); this.refresh();
} }
notesReloadedListener(data) { entitiesReloadedListener(data) {
super.notesReloadedListener(data); super.entitiesReloadedListener(data);
return false; // stop propagation to children return false; // stop propagation to children
} }

View File

@ -427,7 +427,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
} }
} }
async notesReloadedListener({loadResults}) { async entitiesReloadedListener({loadResults}) {
const activeNode = this.getActiveNode(); const activeNode = this.getActiveNode();
const activateNotePath = activeNode ? await treeService.getNotePath(activeNode) : null; const activateNotePath = activeNode ? await treeService.getNotePath(activeNode) : null;
@ -511,7 +511,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
// activateNotePath = appContext.getActiveTabNotePath(); // activateNotePath = appContext.getActiveTabNotePath();
// } // }
// //
// appContext.trigger('notesReloaded', { noteIds, activateNotePath }); // appContext.trigger('entitiesReloaded', { noteIds, activateNotePath });
// } // }
async reloadTreeListener() { async reloadTreeListener() {

View File

@ -60,7 +60,7 @@ export default class TabAwareWidget extends BasicWidget {
this.activeTabChanged(); this.activeTabChanged();
} }
notesReloadedListener({loadResults}) { entitiesReloadedListener({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) { if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
this.refreshWithNote(this.note, this.notePath); this.refreshWithNote(this.note, this.notePath);
} }