DB performance: WAL mode, indexes, query optimization, and by-ID image serving #128

Merged
coding-agent-marvin8 merged 0 commits from refs/pull/128/head into main 2026-07-25 03:04:28 +00:00
coding-agent-marvin8 commented 2026-07-25 01:17:57 +00:00 (Migrated from codeberg.org)

Summary

Four changes to improve database performance, especially at ~30k snapshots:

  1. WAL modePRAGMA journal_mode=WAL + synchronous=NORMAL so periodic scan writes no longer block web UI reads
  2. Two new indexes (schema V4) — (camera, recorded_at) for scrubber/day queries, (motion, recorded_at) for motion range queries
  3. Query rewritesDATE(recorded_at) = ? → range scans (recorded_at >= ? AND recorded_at < ?) so the new indexes are actually used
  4. By-ID image servingGET /snapshots/{id}/img with PK lookup, instead of re-running list_snapshots_for_day on every scrubber frame

Closes #127

## Summary Four changes to improve database performance, especially at ~30k snapshots: 1. **WAL mode** — `PRAGMA journal_mode=WAL` + `synchronous=NORMAL` so periodic scan writes no longer block web UI reads 2. **Two new indexes** (schema V4) — `(camera, recorded_at)` for scrubber/day queries, `(motion, recorded_at)` for motion range queries 3. **Query rewrites** — `DATE(recorded_at) = ?` → range scans (`recorded_at >= ? AND recorded_at < ?`) so the new indexes are actually used 4. **By-ID image serving** — `GET /snapshots/{id}/img` with PK lookup, instead of re-running `list_snapshots_for_day` on every scrubber frame Closes #127
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marvin8/cang!128
No description provided.