fix(db): drop redundant quarantine user index + tighten ListQuarantineForUser

- Composite PK (user_id, track_id) already serves WHERE user_id queries;
  the secondary (user_id, created_at DESC) index just amplified writes.
- ListQuarantineForUser now selects only the joined fields the SPA card
  actually renders (~10 columns) rather than embedding three full structs
  (~35 columns); halves wire/DB bandwidth before consumers exist.
- max(q.created_at)::timestamptz cast emits pgtype.Timestamptz instead of
  interface{} so handlers can read latest_at without a type-assert.
This commit is contained in:
2026-04-30 16:54:03 -04:00
parent a8df73fe42
commit 71a9bd8dee
4 changed files with 50 additions and 51 deletions
@@ -21,8 +21,11 @@ CREATE TABLE lidarr_quarantine (
PRIMARY KEY (user_id, track_id)
);
-- Only the track_id index is non-redundant: the composite PK
-- (user_id, track_id) already serves WHERE user_id = $1 lookups, so a
-- separate (user_id, created_at DESC) index would just amplify writes
-- without paying for itself at household-scale row counts.
CREATE INDEX lidarr_quarantine_track_idx ON lidarr_quarantine (track_id);
CREATE INDEX lidarr_quarantine_user_idx ON lidarr_quarantine (user_id, created_at DESC);
CREATE TYPE lidarr_quarantine_action_kind AS ENUM (
'resolved', 'deleted_file', 'deleted_via_lidarr'