mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 23:13:43 +08:00
fix infinite recursion, closes #2292
This commit is contained in:
parent
e42357f1f8
commit
ce57a13002
1 changed files with 31 additions and 21 deletions
|
@ -45,33 +45,33 @@ class Note extends AbstractEntity {
|
||||||
update([noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified]) {
|
update([noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified]) {
|
||||||
// ------ Database persisted attributes ------
|
// ------ Database persisted attributes ------
|
||||||
|
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.noteId = noteId;
|
this.noteId = noteId;
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.title = title;
|
this.title = title;
|
||||||
/** @param {boolean} */
|
/** @type {boolean} */
|
||||||
this.isProtected = !!isProtected;
|
this.isProtected = !!isProtected;
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.type = type;
|
this.type = type;
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.mime = mime;
|
this.mime = mime;
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.dateCreated = dateCreated || dateUtils.localNowDateTime();
|
this.dateCreated = dateCreated || dateUtils.localNowDateTime();
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.dateModified = dateModified;
|
this.dateModified = dateModified;
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.utcDateCreated = utcDateCreated || dateUtils.utcNowDateTime();
|
this.utcDateCreated = utcDateCreated || dateUtils.utcNowDateTime();
|
||||||
/** @param {string} */
|
/** @type {string} */
|
||||||
this.utcDateModified = utcDateModified;
|
this.utcDateModified = utcDateModified;
|
||||||
|
|
||||||
// ------ Derived attributes ------
|
// ------ Derived attributes ------
|
||||||
|
|
||||||
/** @param {boolean} */
|
/** @type {boolean} */
|
||||||
this.isDecrypted = !this.noteId || !this.isProtected;
|
this.isDecrypted = !this.noteId || !this.isProtected;
|
||||||
|
|
||||||
this.decrypt();
|
this.decrypt();
|
||||||
|
|
||||||
/** @param {string|null} */
|
/** @type {string|null} */
|
||||||
this.flatTextCache = null;
|
this.flatTextCache = null;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -729,23 +729,33 @@ class Note extends AbstractEntity {
|
||||||
|
|
||||||
/** @returns {Note[]} */
|
/** @returns {Note[]} */
|
||||||
getSubtreeNotesIncludingTemplated() {
|
getSubtreeNotesIncludingTemplated() {
|
||||||
const arr = [[this]];
|
const set = new Set();
|
||||||
|
|
||||||
for (const childNote of this.children) {
|
function inner(note) {
|
||||||
arr.push(childNote.getSubtreeNotesIncludingTemplated());
|
if (set.has(note)) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const targetRelation of this.targetRelations) {
|
set.add(note);
|
||||||
if (targetRelation.name === 'template') {
|
|
||||||
const note = targetRelation.note;
|
|
||||||
|
|
||||||
if (note) {
|
for (const childNote of note.children) {
|
||||||
arr.push(note.getSubtreeNotesIncludingTemplated());
|
inner(childNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const targetRelation of note.targetRelations) {
|
||||||
|
if (targetRelation.name === 'template') {
|
||||||
|
const targetNote = targetRelation.note;
|
||||||
|
|
||||||
|
if (targetNote) {
|
||||||
|
inner(targetNote);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr.flat();
|
inner(this);
|
||||||
|
|
||||||
|
return Array.from(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {Note[]} */
|
/** @returns {Note[]} */
|
||||||
|
|
Loading…
Reference in a new issue