prevent cycles in resolving the notepath, fixes #1730

This commit is contained in:
zadam 2021-03-10 22:54:55 +01:00
parent a33ac65fdf
commit 09e9ac4d00
2 changed files with 21 additions and 4 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "trilium",
"version": "0.46.2-beta",
"version": "0.46.3-beta",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -254,22 +254,39 @@ class NoteShort {
return noteAttributeCache.attributes[this.noteId];
}
getAllNotePaths() {
getAllNotePaths(encounteredNoteIds = null) {
if (this.noteId === 'root') {
return [['root']];
}
if (!encounteredNoteIds) {
encounteredNoteIds = new Set();
}
encounteredNoteIds.add(this.noteId);
const parentNotes = this.getParentNotes();
let paths;
if (parentNotes.length === 1) { // optimization for the most common case
paths = parentNotes[0].getAllNotePaths();
if (encounteredNoteIds.has(parentNotes[0].noteId)) {
return [];
}
else {
paths = parentNotes[0].getAllNotePaths(encounteredNoteIds);
}
}
else {
paths = [];
for (const parentNote of parentNotes) {
paths.push(...parentNote.getAllNotePaths());
if (encounteredNoteIds.has(parentNote.noteId)) {
continue;
}
const newSet = new Set(encounteredNoteIds);
paths.push(...parentNote.getAllNotePaths(newSet));
}
}