Skip to content

Build your personal knowledge base with Trilium Notes

fix template attribute cycle in note cache

zadame817acba4e67
diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js
index 4095892637..8cd578e7b3 100644
--- a/src/services/note_cache/entities/note.js
+++ b/src/services/note_cache/entities/note.js
@@ -60,12 +60,21 @@ class Note {
/** @return {Attribute[]} */
get attributes() {
+ return this.__getAttributes([]);
+ }
+
+ __getAttributes(path) {
+ if (path.includes(this.noteId)) {
+ return [];
+ }
+
if (!this.attributeCache) {
const parentAttributes = this.ownedAttributes.slice();
+ const newPath = [...path, this.noteId];
if (this.noteId !== 'root') {
for (const parentNote of this.parents) {
- parentAttributes.push(...parentNote.inheritableAttributes);
+ parentAttributes.push(...parentNote.__getInheritableAttributes(newPath));
}
}
@@ -76,7 +85,7 @@ class Note {
const templateNote = this.noteCache.notes[ownedAttr.value];
if (templateNote) {
- templateAttributes.push(...templateNote.attributes);
+ templateAttributes.push(...templateNote.__getAttributes(newPath));
}
}
}
@@ -95,9 +104,13 @@ class Note {
}
/** @return {Attribute[]} */
- get inheritableAttributes() {
+ __getInheritableAttributes(path) {
+ if (path.includes(this.noteId)) {
+ return [];
+ }
+
if (!this.inheritableAttributeCache) {
- this.attributes; // will refresh also this.inheritableAttributeCache
+ this.__getAttributes(path); // will refresh also this.inheritableAttributeCache
}
return this.inheritableAttributeCache;