From 4c07ac4c4cc400afc4eb8022944f761bcd938f72 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 1 Dec 2019 14:30:59 +0100 Subject: [PATCH] optimized edited notes on day query --- src/routes/api/note_revisions.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.js index 1e7aa05d5..a6922e0b3 100644 --- a/src/routes/api/note_revisions.js +++ b/src/routes/api/note_revisions.js @@ -115,12 +115,17 @@ async function getEditedNotesOnDate(req) { const date = utils.sanitizeSql(req.params.date); const notes = await repository.getEntities(` - select distinct notes.* - from notes - left join note_revisions using (noteId) - where notes.dateCreated LIKE '${date}%' - OR notes.dateModified LIKE '${date}%' - OR note_revisions.dateLastEdited LIKE '${date}%'`); + SELECT notes.* + FROM notes + WHERE noteId IN ( + SELECT noteId FROM notes + WHERE notes.dateCreated LIKE '${date}%' + OR notes.dateModified LIKE '${date}%' + UNION ALL + SELECT noteId FROM note_revisions + WHERE note_revisions.dateLastEdited LIKE '${date}%' + ) + ORDER BY isDeleted`); for (const note of notes) { const notePath = noteCacheService.getNotePath(note.noteId);