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
+14 -7
View File
@@ -17,13 +17,20 @@ DELETE FROM lidarr_quarantine
RETURNING user_id, track_id, reason, notes, created_at;
-- name: ListQuarantineForUser :many
-- Caller's own quarantines joined with track + album + artist for full
-- detail. Drives /library/hidden.
-- Caller's own quarantines plus just the joined fields the SPA's
-- /library/hidden actually renders. Embedding the full tracks/albums/artists
-- structs would drag ~28 columns of file_path / sort_* / mbid / etc. that
-- the row card never uses.
SELECT
sqlc.embed(q),
sqlc.embed(t),
sqlc.embed(al),
sqlc.embed(ar)
t.id AS track_id_join,
t.title AS track_title,
t.duration_ms AS track_duration_ms,
al.id AS album_id,
al.title AS album_title,
al.cover_art_path AS album_cover_art_path,
ar.id AS artist_id,
ar.name AS artist_name
FROM lidarr_quarantine q
JOIN tracks t ON t.id = q.track_id
JOIN albums al ON al.id = t.album_id
@@ -42,8 +49,8 @@ SELECT
al.title AS album_title,
al.id AS album_id,
al.mbid AS lidarr_album_mbid,
count(q.user_id)::int AS report_count,
max(q.created_at) AS latest_at
count(q.user_id)::int AS report_count,
max(q.created_at)::timestamptz AS latest_at
FROM lidarr_quarantine q
JOIN tracks t ON t.id = q.track_id
JOIN albums al ON al.id = t.album_id