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[] {