fix(playlists): each daily mix keeps its id across rebuilds (#8081)
The nightly rebuild deleted every system playlist and inserted new rows, so each mix got a new id every day. A Subsonic app caches, pins, downloads and syncs a playlist by id, and saw its mixes deleted and recreated daily: a stored mix answered "not found" and an offline download was orphaned. The rebuild now refills yesterday's row for the same mix in place (keyed by kind, plus the seed artist for "Songs like" and the name for a genre mix), inserts only mixes that are new, and deletes the ones today's build didn't make, along with their collage files. The rollups move updated_at, which is the "changed" time Subsonic apps use to see a mix was refreshed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,10 +214,27 @@ SELECT COALESCE(
|
||||
LIMIT 1)
|
||||
)::uuid AS id;
|
||||
|
||||
-- name: DeleteSystemPlaylistsForUser :exec
|
||||
-- Atomic-replace step. CASCADE on playlist_tracks.playlist_id handles
|
||||
-- the join rows.
|
||||
DELETE FROM playlists WHERE user_id = $1 AND kind = 'system';
|
||||
-- name: ListSystemPlaylistsForRebuild :many
|
||||
-- The user's current mixes, so a rebuild can refill each in place and keep
|
||||
-- its id.
|
||||
SELECT id, name, system_variant, seed_artist_id
|
||||
FROM playlists
|
||||
WHERE user_id = $1 AND kind = 'system';
|
||||
|
||||
-- name: RefreshSystemPlaylist :exec
|
||||
-- A rebuild refilling an existing mix: its name, description and shelf
|
||||
-- place may move with the day's build. updated_at moves with the rollups.
|
||||
UPDATE playlists
|
||||
SET name = $2, description = sqlc.arg(description), shelf_rank = sqlc.arg(shelf_rank)
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ClearPlaylistTracks :exec
|
||||
DELETE FROM playlist_tracks WHERE playlist_id = $1;
|
||||
|
||||
-- name: DeletePlaylistsByIDs :exec
|
||||
-- Mixes a rebuild no longer makes. CASCADE on playlist_tracks.playlist_id
|
||||
-- handles the join rows.
|
||||
DELETE FROM playlists WHERE id = ANY(sqlc.arg(ids)::uuid[]);
|
||||
|
||||
-- name: ListPlaylistsByUserAndKind :many
|
||||
-- Used in integration tests; production filter applied in Go
|
||||
|
||||
Reference in New Issue
Block a user