docs: query comments say what each query selects and why, not how it came to be (#6277)
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>
This commit is contained in:
@@ -29,7 +29,7 @@ dormant_artists AS (
|
||||
SELECT t.id, t.album_id, t.artist_id
|
||||
FROM tracks t
|
||||
JOIN dormant_artists da ON da.id = t.artist_id
|
||||
WHERE t.missing_since IS NULL -- #2523: never offer a file that is gone
|
||||
WHERE t.missing_since IS NULL -- never offer a file that is gone
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM play_events pe
|
||||
WHERE pe.user_id = $1
|
||||
@@ -56,12 +56,12 @@ SELECT t.id, t.album_id, t.artist_id
|
||||
--
|
||||
-- GROUP BY (not SELECT DISTINCT) so the md5 ORDER BY expression need
|
||||
-- not appear in the select list — Postgres rejects DISTINCT + ORDER BY
|
||||
-- by-expression at plan time (SQLSTATE 42P10), which previously caused
|
||||
-- the entire Discover build to fail silently.
|
||||
-- by-expression at plan time (SQLSTATE 42P10), which would fail the
|
||||
-- entire Discover build.
|
||||
SELECT t.id, t.album_id, t.artist_id
|
||||
FROM general_likes gl
|
||||
JOIN tracks t ON t.id = gl.track_id
|
||||
WHERE t.missing_since IS NULL -- #2523: never offer a file that is gone
|
||||
WHERE t.missing_since IS NULL -- never offer a file that is gone
|
||||
AND gl.user_id != $1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM play_events pe
|
||||
@@ -88,7 +88,7 @@ SELECT t.id, t.album_id, t.artist_id
|
||||
-- $1 = user_id, $2 = date string for md5 ordering.
|
||||
SELECT t.id, t.album_id, t.artist_id
|
||||
FROM tracks t
|
||||
WHERE t.missing_since IS NULL -- #2523: never offer a file that is gone
|
||||
WHERE t.missing_since IS NULL -- never offer a file that is gone
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM play_events pe
|
||||
WHERE pe.user_id = $1
|
||||
@@ -108,7 +108,7 @@ SELECT t.id, t.album_id, t.artist_id
|
||||
|
||||
-- name: ListTasteUnheardTracksForDiscover :many
|
||||
-- Taste-targeted novelty: unheard tracks whose genres overlap the user's
|
||||
-- taste-profile tags (taste_profile_tags, #796), ranked by summed tag
|
||||
-- taste-profile tags (taste_profile_tags), ranked by summed tag
|
||||
-- weight — "new to you, but your vibe" rather than the crude random arm.
|
||||
-- Genres live inline on tracks.genre as a delimited string, split the
|
||||
-- same way the radio tag_overlap arm does (regexp_split_to_table on
|
||||
@@ -116,13 +116,13 @@ SELECT t.id, t.album_id, t.artist_id
|
||||
-- when the user has no taste tags yet (cold start), so the caller
|
||||
-- redistributes its slots to the other buckets. Stamped 'taste_unheard'.
|
||||
--
|
||||
-- The per-album and per-artist caps apply BEFORE the LIMIT (#5356). Summed
|
||||
-- weight rewards a track for carrying many of the user's tags, so a few
|
||||
-- artists whose every track is tagged with the whole profile take every row
|
||||
-- of a plain LIMIT; the caller's caps then left 6 of 120 on the deploy, and
|
||||
-- the best-performing arm handed its slots to the others. Ranking within
|
||||
-- album, then within artist over what the album cap kept, is the same walk
|
||||
-- capByAlbumAndArtist makes, so the caller's caps keep everything here.
|
||||
-- The per-album and per-artist caps apply BEFORE the LIMIT. Summed weight
|
||||
-- rewards a track for carrying many of the user's tags, so a few artists
|
||||
-- whose every track is tagged with the whole profile would take every row of
|
||||
-- a plain LIMIT, the caller's caps would then leave a handful, and the arm
|
||||
-- would hand its slots to the others. Ranking within album, then within
|
||||
-- artist over what the album cap kept, is the same walk capByAlbumAndArtist
|
||||
-- makes, so the caller's caps keep everything here.
|
||||
WITH scored AS (
|
||||
SELECT t.id, t.album_id, t.artist_id,
|
||||
SUM(nt.weight) AS weight,
|
||||
@@ -130,7 +130,7 @@ WITH scored AS (
|
||||
FROM tracks t
|
||||
JOIN LATERAL regexp_split_to_table(coalesce(t.genre, ''), '[;,]') AS g_split(g) ON true
|
||||
JOIN taste_profile_tags nt ON nt.user_id = sqlc.arg(user_id) AND trim(g_split.g) = nt.tag
|
||||
WHERE t.missing_since IS NULL -- #2523: never offer a file that is gone
|
||||
WHERE t.missing_since IS NULL -- never offer a file that is gone
|
||||
AND nt.weight > 0
|
||||
AND trim(g_split.g) <> ''
|
||||
AND NOT EXISTS (
|
||||
|
||||
Reference in New Issue
Block a user