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
optimization of search
zadam172f3689faef
diff --git a/src/services/note_cache/note_cache_service.js b/src/services/note_cache/note_cache_service.jsindex 5eaa725b56..234d6ed172 100644--- a/src/services/note_cache/note_cache_service.js+++ b/src/services/note_cache/note_cache_service.js@@ -152,6 +152,12 @@ function getSomePath(note, path = []) {function getNotePath(noteId) {const note = noteCache.notes[noteId];++ if (!note) {+ console.trace(`Cannot find note ${noteId} in cache.`);+ return;+ }+const retPath = getSomePath(note);if (retPath) {diff --git a/src/services/search/note_set.js b/src/services/search/note_set.jsindex 3f8dc9dcf4..626730d68a 100644--- a/src/services/search/note_set.js+++ b/src/services/search/note_set.js@@ -4,6 +4,7 @@ class NoteSet {constructor(notes = []) {/** @type {Note[]} */this.notes = notes;+ this.noteIdSet = new Set(notes.map(note => note.noteId));/** @type {boolean} */this.sorted = false;}@@ -11,6 +12,7 @@ class NoteSet {add(note) {if (!this.hasNote(note)) {this.notes.push(note);+ this.noteIdSet.add(note.noteId);}}@@ -25,12 +27,12 @@ class NoteSet {}hasNoteId(noteId) {- // TODO: optimize- return !!this.notes.find(note => note.noteId === noteId);+ return this.noteIdSet.has(noteId);}mergeIn(anotherNoteSet) {this.notes = this.notes.concat(anotherNoteSet.notes);+ this.noteIdSet = new Set(this.notes.map(note => note.noteId));}minus(anotherNoteSet) {