mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
optimization of recursive CTE attribute query
This commit is contained in:
parent
8c3e2e5eb7
commit
35cd7f3261
@ -349,11 +349,10 @@ class Note extends Entity {
|
|||||||
tree(noteId, level) AS (
|
tree(noteId, level) AS (
|
||||||
SELECT ?, 0
|
SELECT ?, 0
|
||||||
UNION
|
UNION
|
||||||
SELECT branches.parentNoteId, tree.level + 1 FROM branches
|
SELECT branches.noteId, tree.level + 1
|
||||||
JOIN tree ON branches.noteId = tree.noteId
|
FROM branches
|
||||||
JOIN notes ON notes.noteId = branches.parentNoteId
|
JOIN tree ON branches.parentNoteId = tree.noteId
|
||||||
WHERE notes.isDeleted = 0
|
WHERE branches.isDeleted = 0
|
||||||
AND branches.isDeleted = 0
|
|
||||||
),
|
),
|
||||||
treeWithAttrs(noteId, level) AS (
|
treeWithAttrs(noteId, level) AS (
|
||||||
SELECT * FROM tree
|
SELECT * FROM tree
|
||||||
|
@ -112,15 +112,15 @@ async function eraseNoteRevision(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getEditedNotesOnDate(req) {
|
async function getEditedNotesOnDate(req) {
|
||||||
const date = req.params.date;
|
const date = utils.sanitizeSql(req.params.date);
|
||||||
|
|
||||||
const notes = await repository.getEntities(`
|
const notes = await repository.getEntities(`
|
||||||
select distinct notes.*
|
select distinct notes.*
|
||||||
from notes
|
from notes
|
||||||
left join note_revisions using (noteId)
|
left join note_revisions using (noteId)
|
||||||
where substr(notes.dateCreated, 0, 11) = ?
|
where notes.dateCreated LIKE '${date}%'
|
||||||
or substr(notes.dateModified, 0, 11) = ?
|
OR notes.dateModified LIKE '${date}%'
|
||||||
or substr(note_revisions.dateLastEdited, 0, 11) = ?`, [date, date, date]);
|
OR note_revisions.dateLastEdited LIKE '${date}%'`);
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
const notePath = noteCacheService.getNotePath(note.noteId);
|
const notePath = noteCacheService.getNotePath(note.noteId);
|
||||||
|
@ -161,7 +161,7 @@ async function wrap(func, query) {
|
|||||||
const result = await func(dbConnection);
|
const result = await func(dbConnection);
|
||||||
|
|
||||||
const milliseconds = Date.now() - startTimestamp;
|
const milliseconds = Date.now() - startTimestamp;
|
||||||
if (milliseconds >= 200) {
|
if (milliseconds >= 300) {
|
||||||
if (query.includes("WITH RECURSIVE")) {
|
if (query.includes("WITH RECURSIVE")) {
|
||||||
log.info(`Slow recursive query took ${milliseconds}ms.`);
|
log.info(`Slow recursive query took ${milliseconds}ms.`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user