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
+40
View File
@@ -4,6 +4,8 @@ import (
"context"
"image"
_ "image/jpeg"
"io"
"log/slog"
"os"
"path/filepath"
"testing"
@@ -74,3 +76,41 @@ func TestGenerateCollage_OneTrack(t *testing.T) {
t.Errorf("dimensions = %dx%d, want 600x600", img.Bounds().Dx(), img.Bounds().Dy())
}
}
// The nightly redraw draws a collage for a playlist that has none, as after
// a restore (which leaves cover_path out and carries no collage files).
func TestRedrawUserPlaylistCollages_DrawsAMissingCollage(t *testing.T) {
pool := dbtest.Pool(t)
ctx := context.Background()
user := seedUser(t, pool, "alice")
tk := seedTrack(t, pool, "Prismatic", "FoO")
dir := t.TempDir()
svc := playlists.NewService(pool, nil, dir)
pl, err := svc.Create(ctx, user.ID, "Restored", "", false)
if err != nil {
t.Fatalf("Create: %v", err)
}
if err := svc.AppendTracks(ctx, user.ID, pl.ID, []pgtype.UUID{tk.ID}); err != nil {
t.Fatalf("AppendTracks: %v", err)
}
// As a restore leaves it: no cover_path, and no file.
if _, err := pool.Exec(ctx, `UPDATE playlists SET cover_path = NULL WHERE id = $1`, pl.ID); err != nil {
t.Fatalf("clear cover_path: %v", err)
}
if err := os.RemoveAll(filepath.Join(dir, "playlist_covers")); err != nil {
t.Fatalf("remove covers: %v", err)
}
playlists.RedrawUserPlaylistCollages(ctx, pool, slog.New(slog.NewTextHandler(io.Discard, nil)), user.ID, dir)
got, err := svc.Get(ctx, user.ID, pl.ID)
if err != nil {
t.Fatalf("Get: %v", err)
}
if got.CoverPath == nil || *got.CoverPath == "" {
t.Fatal("no collage after the redraw")
}
if _, err := os.Stat(filepath.Join(dir, *got.CoverPath)); err != nil {
t.Fatalf("collage file: %v", err)
}
}