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
faster implementation of ancestors
zadame2490f99754d
diff --git a/src/services/search/expressions/descendant_of.js b/src/services/search/expressions/descendant_of.jsindex 0d72980773..51e01748ab 100644--- a/src/services/search/expressions/descendant_of.js+++ b/src/services/search/expressions/descendant_of.js@@ -2,6 +2,7 @@const Expression = require('./expression');const NoteSet = require('../note_set');+const noteCache = require('../../note_cache/note_cache');class DescendantOfExp extends Expression {constructor(subExpression) {@@ -11,19 +12,16 @@ class DescendantOfExp extends Expression {}execute(inputNoteSet, searchContext) {- const resNoteSet = new NoteSet();+ const subInputNoteSet = new NoteSet(Object.values(noteCache.notes));+ const subResNoteSet = this.subExpression.execute(subInputNoteSet, searchContext);- for (const note of inputNoteSet.notes) {- const subInputNoteSet = new NoteSet(note.ancestors);+ const subTreeNoteSet = new NoteSet();- const subResNoteSet = this.subExpression.execute(subInputNoteSet, searchContext);-- if (subResNoteSet.notes.length > 0) {- resNoteSet.add(note);- }+ for (const note of subResNoteSet.notes) {+ subTreeNoteSet.addAll(note.subtreeNotes);}- return resNoteSet;+ return inputNoteSet.intersection(subTreeNoteSet);}}