mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixed cleanup of deleted notes for protected notes
This commit is contained in:
parent
7691a59977
commit
8299524682
@ -374,19 +374,12 @@ async function deleteNote(branch) {
|
|||||||
async function cleanupDeletedNotes() {
|
async function cleanupDeletedNotes() {
|
||||||
const cutoffDate = new Date(new Date().getTime() - 48 * 3600 * 1000);
|
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) {
|
await sql.execute("UPDATE notes SET content = NULL WHERE isDeleted = 1 AND content IS NOT NULL AND dateModified <= ?", [dateUtils.dateStr(cutoffDate)]);
|
||||||
note.content = null;
|
|
||||||
await note.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
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)]);
|
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)]);
|
||||||
|
|
||||||
for (const noteRevision of notesRevisionsForCleanup) {
|
|
||||||
noteRevision.content = null;
|
|
||||||
await noteRevision.save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// first cleanup kickoff 5 minutes after startup
|
// first cleanup kickoff 5 minutes after startup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user