added ancestor

This commit is contained in:
zadam
2020-05-23 23:44:55 +02:00
parent 8ce2afff8a
commit 9ede77aead
5 changed files with 132 additions and 1 deletions

View File

@@ -53,6 +53,9 @@ class Note {
if (protectedSessionService.isProtectedSessionAvailable()) {
this.decrypt();
}
/** @param {Note[]|null} */
this.ancestorCache = null;
}
/** @return {Attribute[]} */
@@ -164,6 +167,7 @@ class Note {
this.attributeCache = null;
this.inheritableAttributeCache = null;
this.ancestorCache = null;
}
invalidateSubtreeCaches() {
@@ -258,6 +262,29 @@ class Note {
return this.attributes.length;
}
get ancestors() {
if (!this.ancestorCache) {
const noteIds = new Set();
this.ancestorCache = [];
for (const parent of this.parents) {
if (!noteIds.has(parent.noteId)) {
this.ancestorCache.push(parent);
noteIds.add(parent.noteId);
}
for (const ancestorNote of parent.ancestors) {
if (!noteIds.has(ancestorNote.noteId)) {
this.ancestorCache.push(ancestorNote);
noteIds.add(ancestorNote.noteId);
}
}
}
}
return this.ancestorCache;
}
/** @return {Note[]} - returns only notes which are templated, does not include their subtrees
* in effect returns notes which are influenced by note's non-inheritable attributes */
get templatedNotes() {