Rewrites the internal/db/queries comments to rule 32 and regenerates dbq, whose doc comments and embedded SQL carry them. The bugs behind the tiered mixes, the md5 order seed, the score bands and the round-robin arms are restated as the constraint each one enforces; counts from one library and stale cross-references are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
892 B
SQL
24 lines
892 B
SQL
-- name: ListUserHistory :many
|
|
-- Track-level listening history. Returns one row per
|
|
-- play_events entry, newest first, joined with tracks/albums/artists
|
|
-- so the SPA can render a TrackRef without follow-up fetches. Filters
|
|
-- out skipped events and tracks the user has quarantined (per-user
|
|
-- soft-hide). $1 = user_id, $2 = limit, $3 = offset.
|
|
SELECT pe.id AS event_id,
|
|
pe.started_at,
|
|
sqlc.embed(t),
|
|
albums.title AS album_title,
|
|
artists.name AS artist_name
|
|
FROM play_events pe
|
|
JOIN tracks t ON t.id = pe.track_id
|
|
JOIN albums ON albums.id = t.album_id
|
|
JOIN artists ON artists.id = t.artist_id
|
|
WHERE pe.user_id = $1
|
|
AND pe.was_skipped = false
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM quarantine q
|
|
WHERE q.user_id = $1 AND q.track_id = t.id
|
|
)
|
|
ORDER BY pe.started_at DESC
|
|
LIMIT $2 OFFSET $3;
|