Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixed search notes with new treecache
zadame04845335b91
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex 3adafda841..370fbb89ad 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -854,7 +854,7 @@ async function reloadNotes(noteIds, activateNotePath = null) {const node = await getNodeFromPath(activateNotePath);if (node) {- await node.setActive(true, {noEvents: true}); // this node has been already active so no need to fire events again+ await node.setActive(true);}}}diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.jsindex a8997c2648..d183a64104 100644--- a/src/public/javascripts/services/tree_builder.js+++ b/src/public/javascripts/services/tree_builder.js@@ -115,21 +115,22 @@ async function prepareSearchBranch(note) {// force to load all the notes at once instead of one by oneawait treeCache.getNotes(results.map(res => res.noteId));- for (const result of results) {- const origBranch = treeCache.getBranch(result.branchId);+ const {notes, branches} = await server.post('tree/load', { noteIds: [note.noteId] });- const branch = new Branch(treeCache, {- branchId: "virt" + utils.randomString(10),- noteId: result.noteId,- parentNoteId: note.noteId,- prefix: origBranch.prefix,- virtual: true- });+ results.forEach((result, index) => branches.push({+ branchId: "virt" + utils.randomString(10),+ noteId: result.noteId,+ parentNoteId: note.noteId,+ prefix: treeCache.getBranch(result.branchId).prefix,+ notePosition: (index + 1) * 10+ }));- treeCache.addBranch(branch);- }+ treeCache.addResp(notes, branches);++ // note in cache changed+ const newNote = await treeCache.getNote(note.noteId);- return await prepareRealBranch(note);+ return await prepareRealBranch(newNote);}async function getExtraClasses(note) {diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.jsindex 3984c04482..8371c2291c 100644--- a/src/public/javascripts/services/tree_cache.js+++ b/src/public/javascripts/services/tree_cache.js@@ -5,6 +5,11 @@ import server from "./server.js";/*** TreeCache keeps a read only cache of note tree structure in frontend's memory.+ * - notes are loaded lazily when unknown noteId is requested+ * - when note is loaded, all its parent and child branches are loaded as well. For a branch to be used, it's not must be loaded before+ * - deleted notes are present in the cache as well, but they don't have any branches. As a result check for deleted branch is done by presence check - if the branch is not there even though the corresponding note has been loaded, we can infer it is deleted.+ *+ * Note and branch deletions are corner cases and usually not needed.*/class TreeCache {constructor() {@@ -50,12 +55,9 @@ class TreeCache {if (childNote) {childNote.parents = childNote.parents.filter(p => p !== noteId);- const branchId = childNote.parentToBranch[noteId];-- if (branchId in this.branches) {- delete this.branches[branchId];- }+ console.log("Cleaning up", childNote.parentToBranch[noteId]);+ delete this.branches[childNote.parentToBranch[noteId]];delete childNote.parentToBranch[noteId];}}@@ -66,19 +68,18 @@ class TreeCache {if (parentNote) {parentNote.children = parentNote.children.filter(p => p !== noteId);- const branchId = parentNote.childToBranch[noteId];-- if (branchId in this.branches) {- delete this.branches[branchId];- }-+ delete this.branches[parentNote.childToBranch[noteId]];delete parentNote.childToBranch[noteId];}}}for (const branch of branchesByNotes[noteId] || []) { // can be empty for deleted notes- this.addBranch(branch);+ if (noteId === '2Ndfjyv3EbEQ') {+ console.log("Adding", branch.branchId);+ }++ this.branches[branch.branchId] = branch;}const note = new NoteShort(this, noteRow, branchesByNotes[noteId] || []);@@ -147,10 +148,6 @@ class TreeCache {return (await this.getNotes([noteId], silentNotFoundError))[0];}- addBranch(branch) {- this.branches[branch.branchId] = branch;- }-getBranches(branchIds) {return branchIds.map(branchId => this.getBranch(branchId))