From 70a69f0ae37968cd3e7fac35f52d5663df916109 Mon Sep 17 00:00:00 2001 From: altair823 Date: Fri, 1 May 2026 20:51:06 +0900 Subject: [PATCH] refactor(trash): emptyTrash uses DELETE...RETURNING (review T4 S1) --- src/main/repository/NoteRepository.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/repository/NoteRepository.ts b/src/main/repository/NoteRepository.ts index 36add73..f980679 100644 --- a/src/main/repository/NoteRepository.ts +++ b/src/main/repository/NoteRepository.ts @@ -243,18 +243,13 @@ export class NoteRepository { } emptyTrash(): { noteIds: string[] } { - const noteIds: string[] = []; - const tx = this.db.transaction(() => { - const rows = this.db - .prepare('SELECT id FROM notes WHERE deleted_at IS NOT NULL') - .all() as Array<{ id: string }>; - for (const r of rows) { - this.db.prepare('DELETE FROM notes WHERE id=?').run(r.id); - noteIds.push(r.id); - } - }); - tx(); - return { noteIds }; + // Single DELETE ... RETURNING is atomic by itself (no explicit transaction needed) + // and avoids per-row prepare overhead. RETURNING is house-style elsewhere + // (updateAiResult/updateUserAiFields/getAllPendingJobs). + const rows = this.db + .prepare('DELETE FROM notes WHERE deleted_at IS NOT NULL RETURNING id') + .all() as Array<{ id: string }>; + return { noteIds: rows.map((r) => r.id) }; } listTrashed(opts: { limit: number }): Note[] {