refactor(trash): emptyTrash uses DELETE...RETURNING (review T4 S1)

This commit is contained in:
altair823
2026-05-01 20:51:06 +09:00
parent 11703b976e
commit 70a69f0ae3

View File

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