Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
optimization of recursive CTE attribute query
zadam35cd7f32619e
diff --git a/src/entities/note.js b/src/entities/note.jsindex 5b7067e7d9..8603225c94 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -349,11 +349,10 @@ class Note extends Entity {tree(noteId, level) AS (SELECT ?, 0UNION- SELECT branches.parentNoteId, tree.level + 1 FROM branches- JOIN tree ON branches.noteId = tree.noteId- JOIN notes ON notes.noteId = branches.parentNoteId- WHERE notes.isDeleted = 0- AND branches.isDeleted = 0+ SELECT branches.noteId, tree.level + 1+ FROM branches+ JOIN tree ON branches.parentNoteId = tree.noteId+ WHERE branches.isDeleted = 0),treeWithAttrs(noteId, level) AS (SELECT * FROM treediff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.jsindex 5943f150b3..1e7aa05d58 100644--- a/src/routes/api/note_revisions.js+++ b/src/routes/api/note_revisions.js@@ -112,15 +112,15 @@ async function eraseNoteRevision(req) {}async function getEditedNotesOnDate(req) {- const date = req.params.date;+ const date = utils.sanitizeSql(req.params.date);const notes = await repository.getEntities(`select distinct notes.*from notesleft join note_revisions using (noteId)- where substr(notes.dateCreated, 0, 11) = ?- or substr(notes.dateModified, 0, 11) = ?- or substr(note_revisions.dateLastEdited, 0, 11) = ?`, [date, date, date]);+ where notes.dateCreated LIKE '${date}%'+ OR notes.dateModified LIKE '${date}%'+ OR note_revisions.dateLastEdited LIKE '${date}%'`);for (const note of notes) {const notePath = noteCacheService.getNotePath(note.noteId);diff --git a/src/services/sql.js b/src/services/sql.jsindex ea88628093..2997293485 100644--- a/src/services/sql.js+++ b/src/services/sql.js@@ -161,7 +161,7 @@ async function wrap(func, query) {const result = await func(dbConnection);const milliseconds = Date.now() - startTimestamp;- if (milliseconds >= 200) {+ if (milliseconds >= 300) {if (query.includes("WITH RECURSIVE")) {log.info(`Slow recursive query took ${milliseconds}ms.`);}