fix(playlists): a restored playlist draws its collage again instead of showing a broken image (#8105)

A collage is a file in the data directory, which the backup doesn't carry,
but playlists.cover_path travelled, so a restored playlist pointed at a file
that wasn't there and its tile showed a broken image until someone edited it.

- The backup leaves cover_path out, so a restored playlist starts with none.
- The nightly rebuild (and the catch-up at startup) draws each person's own
  playlist collages again from their albums' current covers, so one drawn
  before the art arrived fills in later.
- The cover endpoint draws a collage whose file has gone missing, rather
  than answering 404.
- SetPlaylistCover only bumps updated_at when the path changes, so a redraw
  isn't a change to the playlist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 23:55:30 -05:00
co-authored by Claude Opus 5.5
parent 436a970f7b
commit dbf39f90f8
7 changed files with 117 additions and 3 deletions
+29 -1
View File
@@ -488,6 +488,31 @@ func (q *Queries) ListPlaylistsForUser(ctx context.Context, userID pgtype.UUID)
return items, nil
}
const listUserPlaylistIDsForOwner = `-- name: ListUserPlaylistIDsForOwner :many
SELECT id FROM playlists WHERE user_id = $1 AND kind = 'user' ORDER BY id
`
// The playlists a person made, not their system mixes.
func (q *Queries) ListUserPlaylistIDsForOwner(ctx context.Context, userID pgtype.UUID) ([]pgtype.UUID, error) {
rows, err := q.db.Query(ctx, listUserPlaylistIDsForOwner, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []pgtype.UUID
for rows.Next() {
var id pgtype.UUID
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const renumberPlaylistTracksAfter = `-- name: RenumberPlaylistTracksAfter :exec
UPDATE playlist_tracks
SET position = position - 1
@@ -506,7 +531,8 @@ func (q *Queries) RenumberPlaylistTracksAfter(ctx context.Context, arg RenumberP
}
const setPlaylistCover = `-- name: SetPlaylistCover :exec
UPDATE playlists SET cover_path = $2, updated_at = now() WHERE id = $1
UPDATE playlists SET cover_path = $2, updated_at = now()
WHERE id = $1 AND cover_path IS DISTINCT FROM $2
`
type SetPlaylistCoverParams struct {
@@ -514,6 +540,8 @@ type SetPlaylistCoverParams struct {
CoverPath *string
}
// Only a changed path counts as a change to the playlist: a collage drawn
// again to the same file leaves updated_at alone.
func (q *Queries) SetPlaylistCover(ctx context.Context, arg SetPlaylistCoverParams) error {
_, err := q.db.Exec(ctx, setPlaylistCover, arg.ID, arg.CoverPath)
return err