|
|
|
|
@ -85,10 +85,14 @@ 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) {
|
|
|
|
|
if (note) {
|
|
|
|
|
note.update(noteRow);
|
|
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
|
|
|
|
|
|
if (childNote) {
|
|
|
|
|
@ -99,23 +103,37 @@ class TreeCache {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const parentNoteId of oldNote.parents) {
|
|
|
|
|
note.children = [];
|
|
|
|
|
note.childToBranch = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 || !branch) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (branch.fromSearchNote) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parentNote) {
|
|
|
|
|
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) {
|
|
|
|
|
const branch = new Branch(this, branchRow);
|
|
|
|
|
|
|
|
|
|
@ -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
|
|
|
|
|
|