mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 15:05:31 +08:00
properly handle saved search virtual branches during reloads, fixes #1301
This commit is contained in:
parent
a9f49e7f25
commit
00d860bfae
4 changed files with 53 additions and 32 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -3095,9 +3095,9 @@
|
|||
}
|
||||
},
|
||||
"electron-rebuild": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.2.0.tgz",
|
||||
"integrity": "sha512-qbrCoBSmbL/f6OwfRXg5cihAJ0TwbgRKmyK7helR6XNlaoPO42ny/+4yCTXJrYa0ZhkvcdY+gZE/wu2p19gFHg==",
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.3.0.tgz",
|
||||
"integrity": "sha512-+2H3xFc9aFFmMcYP6AOYBcY1gJd+aYlglBBXUnkyXd0ZAqM9y6LWND4UEBPncVTAJ2q6neKLPR7RLceIxgyukA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@malept/cross-spawn-promise": "^1.1.0",
|
||||
|
@ -3115,9 +3115,9 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@sindresorhus/is": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-3.1.2.tgz",
|
||||
"integrity": "sha512-JiX9vxoKMmu8Y3Zr2RVathBL1Cdu4Nt4MuNWemt1Nc06A0RAin9c5FArkhGsyMBWfCu4zj+9b+GxtjAnE4qqLQ==",
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz",
|
||||
"integrity": "sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@szmarczak/http-timer": {
|
||||
|
@ -3169,12 +3169,12 @@
|
|||
}
|
||||
},
|
||||
"got": {
|
||||
"version": "11.7.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-11.7.0.tgz",
|
||||
"integrity": "sha512-7en2XwH2MEqOsrK0xaKhbWibBoZqy+f1RSUoIeF1BLcnf+pyQdDsljWMfmOh+QKJwuvDIiKx38GtPh5wFdGGjg==",
|
||||
"version": "11.8.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.0.tgz",
|
||||
"integrity": "sha512-k9noyoIIY9EejuhaBNLyZ31D5328LeqnyPNXJQb2XlJZcKakLqN5m6O/ikhq/0lw56kUYS54fVm+D1x57YC9oQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sindresorhus/is": "^3.1.1",
|
||||
"@sindresorhus/is": "^4.0.0",
|
||||
"@szmarczak/http-timer": "^4.0.5",
|
||||
"@types/cacheable-request": "^6.0.1",
|
||||
"@types/responselike": "^1.0.0",
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
"electron": "9.3.2",
|
||||
"electron-builder": "22.9.1",
|
||||
"electron-packager": "15.1.0",
|
||||
"electron-rebuild": "2.2.0",
|
||||
"electron-rebuild": "2.3.0",
|
||||
"esm": "3.2.25",
|
||||
"jasmine": "3.6.2",
|
||||
"jsdoc": "3.6.6",
|
||||
|
|
|
@ -21,6 +21,8 @@ class Branch {
|
|||
this.isExpanded = !!row.isExpanded;
|
||||
/** @param {boolean} */
|
||||
this.isDeleted = !!row.isDeleted;
|
||||
/** @param {boolean} */
|
||||
this.fromSearchNote = !!row.fromSearchNote;
|
||||
}
|
||||
|
||||
/** @returns {NoteShort} */
|
||||
|
@ -48,4 +50,4 @@ class Branch {
|
|||
}
|
||||
}
|
||||
|
||||
export default Branch;
|
||||
export default Branch;
|
||||
|
|
|
@ -85,35 +85,53 @@ class TreeCache {
|
|||
for (const noteRow of noteRows) {
|
||||
const {noteId} = noteRow;
|
||||
|
||||
const oldNote = this.notes[noteId];
|
||||
let note = this.notes[noteId];
|
||||
|
||||
if (oldNote) {
|
||||
for (const childNoteId of oldNote.children) {
|
||||
const childNote = this.notes[childNoteId];
|
||||
if (note) {
|
||||
note.update(noteRow);
|
||||
|
||||
if (childNote) {
|
||||
childNote.parents = childNote.parents.filter(p => p !== noteId);
|
||||
// search note doesn't have child branches in database and all the children are virtual branches
|
||||
if (note.type !== 'search') {
|
||||
for (const childNoteId of note.children) {
|
||||
const childNote = this.notes[childNoteId];
|
||||
|
||||
delete this.branches[childNote.parentToBranch[noteId]];
|
||||
delete childNote.parentToBranch[noteId];
|
||||
if (childNote) {
|
||||
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 branch = this.branches[parentNote.childToBranch[noteId]];
|
||||
|
||||
if (parentNote) {
|
||||
parentNote.children = parentNote.children.filter(p => p !== noteId);
|
||||
|
||||
delete this.branches[parentNote.childToBranch[noteId]];
|
||||
delete parentNote.childToBranch[noteId];
|
||||
if (!parentNote || !branch) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -187,7 +205,8 @@ class TreeCache {
|
|||
branchId: "virt" + resultNoteId + '-' + note.noteId,
|
||||
noteId: resultNoteId,
|
||||
parentNoteId: note.noteId,
|
||||
notePosition: (index + 1) * 10
|
||||
notePosition: (index + 1) * 10,
|
||||
fromSearchNote: true
|
||||
}));
|
||||
|
||||
// update this note with standard (parent) branches + virtual (children) branches
|
||||
|
|
Loading…
Reference in a new issue