fix(trash): close active-query invariant leaks (review T5 important #1+#2)
T5 reviewer identified 2 reads outside NoteRepository that were missing the 'WHERE deleted_at IS NULL' filter, breaking the silent invariant beyond the 3 originally-listed methods. - ContinuityService.get() now excludes trashed notes from streak / weekCount / lastNoteAt / recovery-toast math. A trashed note no longer counts toward weekly streak (regression: streak felt fake after trash). - NoteRepository.getPendingCount() now excludes trashed-but-still-pending notes. trash() removes the pending_jobs row but leaves notes.ai_status='pending'; the count would have drifted upward as users trashed pending notes. - MediaGc.run() gets an inline comment documenting why it intentionally does NOT filter — trashed notes still own their media until permanentDelete / emptyTrash. Removing here would defeat restore. Also: migrations.due_date.test.ts had 2 brittle assertions (latestVersion()===2, user_version===2) that broke with v3. Migration-system version assertions belong in migrations.test.ts (already covered there); m002-specific test keeps the due_date column assertion which is version-stable. Tests: 245 → 265 (+20). typecheck 0 errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -345,7 +345,9 @@ export class NoteRepository {
|
||||
|
||||
getPendingCount(): number {
|
||||
const row = this.db
|
||||
.prepare(`SELECT COUNT(*) AS c FROM notes WHERE ai_status='pending'`)
|
||||
.prepare(
|
||||
`SELECT COUNT(*) AS c FROM notes WHERE ai_status='pending' AND deleted_at IS NULL`
|
||||
)
|
||||
.get() as { c: number };
|
||||
return row.c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user