Skip to content

Build your personal knowledge base with Trilium Notes

fix for clones & optimizations

azivner85a974829191
diff --git a/src/public/javascripts/entities/note_short.js b/src/public/javascripts/entities/note_short.js
index f98cd5cc05..c1a3f74c04 100644
--- a/src/public/javascripts/entities/note_short.js
+++ b/src/public/javascripts/entities/note_short.js
@@ -36,20 +36,20 @@ class NoteShort {
return await this.treeCache.getBranches(branchIds);
}
- async __getNotes(noteIds) {
- if (!noteIds) {
- return [];
- }
-
- return this.treeCache.getNotes(noteIds);
+ getParentNoteIds() {
+ return this.treeCache.parents[this.noteId] || [];
}
async getParentNotes() {
- return this.__getNotes(this.treeCache.parents[this.noteId]);
+ return await this.treeCache.getNotes(this.getParentNoteIds());
+ }
+
+ getChildNoteIds() {
+ return this.treeCache.children[this.noteId] || [];
}
async getChildNotes() {
- return this.__getNotes(this.treeCache.children[this.noteId]);
+ return await this.treeCache.getNotes(this.getChildNoteIds());
}
get toString() {
diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js
index 2c9515323e..0c8bb5cdb5 100644
--- a/src/public/javascripts/services/tree_builder.js
+++ b/src/public/javascripts/services/tree_builder.js
@@ -94,7 +94,7 @@ async function getExtraClasses(note) {
extraClasses.push("protected");
}
- if ((await note.getParentNotes()).length > 1) {
+ if (note.getParentNoteIds().length > 1) {
extraClasses.push("multiple-parents");
}
diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js
index 98ed5afd8d..40f26aff15 100644
--- a/src/routes/api/tree.js
+++ b/src/routes/api/tree.js
@@ -19,12 +19,15 @@ async function getNotes(noteIds) {
async function getRelations(noteIds) {
const questionMarks = noteIds.map(() => "?").join(",");
+ const doubledNoteIds = noteIds.concat(noteIds);
return await sql.getRows(`SELECT branchId, noteId AS 'childNoteId', parentNoteId FROM branches WHERE isDeleted = 0
- AND parentNoteId IN (${questionMarks})`, noteIds);
+ AND (parentNoteId IN (${questionMarks}) OR noteId IN (${questionMarks}))`, doubledNoteIds);
}
async function getTree() {
+ // we fetch all branches of notes, even if that particular branch isn't visible
+ // this allows us to e.g. detect and properly display clones
const branches = await sql.getRows(`
WITH RECURSIVE
tree(branchId, noteId, isExpanded) AS (
@@ -34,7 +37,7 @@ async function getTree() {
JOIN tree ON branches.parentNoteId = tree.noteId
WHERE tree.isExpanded = 1 AND branches.isDeleted = 0
)
- SELECT branches.* FROM tree JOIN branches USING(branchId);`);
+ SELECT branches.* FROM tree JOIN branches USING(noteId)`);
const noteIds = branches.map(b => b.noteId);