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
+23
View File
@@ -7,6 +7,7 @@ import (
"image/color"
"image/draw"
"image/jpeg"
"log/slog"
"os"
"path/filepath"
"strings"
@@ -239,3 +240,25 @@ func pgtypeUUIDStringForCollage(u pgtype.UUID) string {
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15])
}
// RedrawUserPlaylistCollages draws the collage of each playlist userID made
// again, from its albums' covers as they are now. The nightly rebuild calls
// it. A collage is otherwise drawn only when a playlist's songs change, so
// without this one drawn before its albums had covers (after a restore, or
// on a library still fetching art) would keep its placeholder cells for good.
// A failure on one playlist is logged and the rest are still drawn.
func RedrawUserPlaylistCollages(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger, userID pgtype.UUID, dataDir string) {
if dataDir == "" {
return
}
ids, err := dbq.New(pool).ListUserPlaylistIDsForOwner(ctx, userID)
if err != nil {
logger.Warn("playlists: list for collage redraw failed", "user_id", pgtypeUUIDStringForCollage(userID), "err", err)
return
}
for _, id := range ids {
if _, err := GenerateCollage(ctx, pool, id, dataDir); err != nil {
logger.Warn("playlists: collage redraw failed", "playlist_id", pgtypeUUIDStringForCollage(id), "err", err)
}
}
}