properly handle saved search virtual branches during reloads, fixes #1301

This commit is contained in:
zadam 2020-10-20 22:33:38 +02:00
parent a9f49e7f25
commit 00d860bfae
4 changed files with 53 additions and 32 deletions

20
package-lock.json generated
View File

@ -3095,9 +3095,9 @@
} }
}, },
"electron-rebuild": { "electron-rebuild": {
"version": "2.2.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.2.0.tgz", "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.3.0.tgz",
"integrity": "sha512-qbrCoBSmbL/f6OwfRXg5cihAJ0TwbgRKmyK7helR6XNlaoPO42ny/+4yCTXJrYa0ZhkvcdY+gZE/wu2p19gFHg==", "integrity": "sha512-+2H3xFc9aFFmMcYP6AOYBcY1gJd+aYlglBBXUnkyXd0ZAqM9y6LWND4UEBPncVTAJ2q6neKLPR7RLceIxgyukA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@malept/cross-spawn-promise": "^1.1.0", "@malept/cross-spawn-promise": "^1.1.0",
@ -3115,9 +3115,9 @@
}, },
"dependencies": { "dependencies": {
"@sindresorhus/is": { "@sindresorhus/is": {
"version": "3.1.2", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-3.1.2.tgz", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz",
"integrity": "sha512-JiX9vxoKMmu8Y3Zr2RVathBL1Cdu4Nt4MuNWemt1Nc06A0RAin9c5FArkhGsyMBWfCu4zj+9b+GxtjAnE4qqLQ==", "integrity": "sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ==",
"dev": true "dev": true
}, },
"@szmarczak/http-timer": { "@szmarczak/http-timer": {
@ -3169,12 +3169,12 @@
} }
}, },
"got": { "got": {
"version": "11.7.0", "version": "11.8.0",
"resolved": "https://registry.npmjs.org/got/-/got-11.7.0.tgz", "resolved": "https://registry.npmjs.org/got/-/got-11.8.0.tgz",
"integrity": "sha512-7en2XwH2MEqOsrK0xaKhbWibBoZqy+f1RSUoIeF1BLcnf+pyQdDsljWMfmOh+QKJwuvDIiKx38GtPh5wFdGGjg==", "integrity": "sha512-k9noyoIIY9EejuhaBNLyZ31D5328LeqnyPNXJQb2XlJZcKakLqN5m6O/ikhq/0lw56kUYS54fVm+D1x57YC9oQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@sindresorhus/is": "^3.1.1", "@sindresorhus/is": "^4.0.0",
"@szmarczak/http-timer": "^4.0.5", "@szmarczak/http-timer": "^4.0.5",
"@types/cacheable-request": "^6.0.1", "@types/cacheable-request": "^6.0.1",
"@types/responselike": "^1.0.0", "@types/responselike": "^1.0.0",

View File

@ -80,7 +80,7 @@
"electron": "9.3.2", "electron": "9.3.2",
"electron-builder": "22.9.1", "electron-builder": "22.9.1",
"electron-packager": "15.1.0", "electron-packager": "15.1.0",
"electron-rebuild": "2.2.0", "electron-rebuild": "2.3.0",
"esm": "3.2.25", "esm": "3.2.25",
"jasmine": "3.6.2", "jasmine": "3.6.2",
"jsdoc": "3.6.6", "jsdoc": "3.6.6",

View File

@ -21,6 +21,8 @@ class Branch {
this.isExpanded = !!row.isExpanded; this.isExpanded = !!row.isExpanded;
/** @param {boolean} */ /** @param {boolean} */
this.isDeleted = !!row.isDeleted; this.isDeleted = !!row.isDeleted;
/** @param {boolean} */
this.fromSearchNote = !!row.fromSearchNote;
} }
/** @returns {NoteShort} */ /** @returns {NoteShort} */

View File

@ -85,35 +85,53 @@ class TreeCache {
for (const noteRow of noteRows) { for (const noteRow of noteRows) {
const {noteId} = noteRow; const {noteId} = noteRow;
const oldNote = this.notes[noteId]; let note = this.notes[noteId];
if (oldNote) { if (note) {
for (const childNoteId of oldNote.children) { note.update(noteRow);
const childNote = this.notes[childNoteId];
if (childNote) { // search note doesn't have child branches in database and all the children are virtual branches
childNote.parents = childNote.parents.filter(p => p !== noteId); if (note.type !== 'search') {
for (const childNoteId of note.children) {
const childNote = this.notes[childNoteId];
delete this.branches[childNote.parentToBranch[noteId]]; if (childNote) {
delete childNote.parentToBranch[noteId]; childNote.parents = childNote.parents.filter(p => p !== noteId);
delete this.branches[childNote.parentToBranch[noteId]];
delete childNote.parentToBranch[noteId];
}
} }
note.children = [];
note.childToBranch = [];
} }
for (const parentNoteId of oldNote.parents) { // we want to remove all "real" branches (represented in the database) since those will be created
// from branches argument but want to preserve all virtual ones from saved search
note.parents = note.parents.filter(parentNoteId => {
const parentNote = this.notes[parentNoteId]; const parentNote = this.notes[parentNoteId];
const branch = this.branches[parentNote.childToBranch[noteId]];
if (parentNote) { if (!parentNote || !branch) {
parentNote.children = parentNote.children.filter(p => p !== noteId); return false;
delete this.branches[parentNote.childToBranch[noteId]];
delete parentNote.childToBranch[noteId];
} }
}
if (branch.fromSearchNote) {
return true;
}
parentNote.children = parentNote.children.filter(p => p !== noteId);
delete this.branches[parentNote.childToBranch[noteId]];
delete parentNote.childToBranch[noteId];
return false;
});
}
else {
this.notes[noteId] = new NoteShort(this, noteRow);
} }
const note = new NoteShort(this, noteRow);
this.notes[note.noteId] = note;
} }
for (const branchRow of branchRows) { for (const branchRow of branchRows) {
@ -187,7 +205,8 @@ class TreeCache {
branchId: "virt" + resultNoteId + '-' + note.noteId, branchId: "virt" + resultNoteId + '-' + note.noteId,
noteId: resultNoteId, noteId: resultNoteId,
parentNoteId: note.noteId, parentNoteId: note.noteId,
notePosition: (index + 1) * 10 notePosition: (index + 1) * 10,
fromSearchNote: true
})); }));
// update this note with standard (parent) branches + virtual (children) branches // update this note with standard (parent) branches + virtual (children) branches