From e817acba4e67b842794079498e8f9e4e406bbd33 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 4 Jun 2020 23:58:31 +0200 Subject: [PATCH] fix template attribute cycle in note cache --- src/services/note_cache/entities/note.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index 409589263..8cd578e7b 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;