From 8299524682b9f3c8bb65eb00b0f14f20771a42eb Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 18 Nov 2018 11:34:40 +0100 Subject: [PATCH] fixed cleanup of deleted notes for protected notes --- src/services/notes.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/services/notes.js b/src/services/notes.js index 4fa7503eb..60db6e40e 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -374,19 +374,12 @@ async function deleteNote(branch) { async function cleanupDeletedNotes() { const cutoffDate = new Date(new Date().getTime() - 48 * 3600 * 1000); - const notesForCleanup = await repository.getEntities("SELECT * FROM notes WHERE isDeleted = 1 AND content != '' AND dateModified <= ?", [dateUtils.dateStr(cutoffDate)]); + // it's better to not use repository for this because it will complain about saving protected notes + // out of protected session - for (const note of notesForCleanup) { - note.content = null; - await note.save(); - } + await sql.execute("UPDATE notes SET content = NULL WHERE isDeleted = 1 AND content IS NOT NULL AND dateModified <= ?", [dateUtils.dateStr(cutoffDate)]); - const notesRevisionsForCleanup = await repository.getEntities("SELECT note_revisions.* FROM notes JOIN note_revisions USING(noteId) WHERE notes.isDeleted = 1 AND note_revisions.content != '' AND notes.dateModified <= ?", [dateUtils.dateStr(cutoffDate)]); - - for (const noteRevision of notesRevisionsForCleanup) { - noteRevision.content = null; - await noteRevision.save(); - } + await sql.execute("UPDATE note_revisions SET content = NULL WHERE note_revisions.content IS NOT NULL AND noteId IN (SELECT noteId FROM notes WHERE isDeleted = 1 AND notes.dateModified <= ?)", [dateUtils.dateStr(cutoffDate)]); } // first cleanup kickoff 5 minutes after startup