refactor(trash): emptyTrash uses DELETE...RETURNING (review T4 S1)
This commit is contained in:
@@ -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[] {
|
||||
|
||||
Reference in New Issue
Block a user