Add lastUpdated to coverArt ids. Helps with invalidating art cache client-side.

This commit is contained in:
Deluan
2023-02-08 13:49:05 -05:00
committed by Deluan Quintão
parent a3b8682d44
commit 806713719f
6 changed files with 105 additions and 52 deletions
+7 -4
View File
@@ -73,6 +73,10 @@ func (a *artwork) Get(ctx context.Context, artID model.ArtworkID, size int) (rea
return r, artReader.LastUpdated(), nil
}
type coverArtGetter interface {
CoverArtID() model.ArtworkID
}
func (a *artwork) getArtworkId(ctx context.Context, id string) (model.ArtworkID, error) {
if id == "" {
return model.ArtworkID{}, ErrUnavailable
@@ -87,18 +91,17 @@ func (a *artwork) getArtworkId(ctx context.Context, id string) (model.ArtworkID,
if err != nil {
return model.ArtworkID{}, err
}
if e, ok := entity.(coverArtGetter); ok {
artID = e.CoverArtID()
}
switch e := entity.(type) {
case *model.Artist:
artID = model.NewArtworkID(model.KindArtistArtwork, e.ID)
log.Trace(ctx, "ID is for an Artist", "id", id, "name", e.Name, "artist", e.Name)
case *model.Album:
artID = model.NewArtworkID(model.KindAlbumArtwork, e.ID)
log.Trace(ctx, "ID is for an Album", "id", id, "name", e.Name, "artist", e.AlbumArtist)
case *model.MediaFile:
artID = model.NewArtworkID(model.KindMediaFileArtwork, e.ID)
log.Trace(ctx, "ID is for a MediaFile", "id", id, "title", e.Title, "album", e.Album)
case *model.Playlist:
artID = model.NewArtworkID(model.KindPlaylistArtwork, e.ID)
log.Trace(ctx, "ID is for a Playlist", "id", id, "name", e.Name)
}
return artID, nil
+3 -3
View File
@@ -49,7 +49,7 @@ var _ = Describe("Artwork", func() {
Describe("albumArtworkReader", func() {
Context("ID not found", func() {
It("returns ErrNotFound if album is not in the DB", func() {
_, err := newAlbumArtworkReader(ctx, aw, model.MustParseArtworkID("al-NOT_FOUND"), nil)
_, err := newAlbumArtworkReader(ctx, aw, model.MustParseArtworkID("al-NOT-FOUND"), nil)
Expect(err).To(MatchError(model.ErrNotFound))
})
})
@@ -157,14 +157,14 @@ var _ = Describe("Artwork", func() {
Expect(err).ToNot(HaveOccurred())
_, path, err := aw.Reader(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("al-444"))
Expect(path).To(Equal("al-444_0"))
})
It("returns album cover if media file has no cover art", func() {
aw, err := newMediafileArtworkReader(ctx, aw, model.MustParseArtworkID("mf-"+mfWithoutEmbed.ID))
Expect(err).ToNot(HaveOccurred())
_, path, err := aw.Reader(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("al-444"))
Expect(path).To(Equal("al-444_0"))
})
})
})
+3 -2
View File
@@ -20,8 +20,9 @@ type cacheKey struct {
func (k *cacheKey) Key() string {
return fmt.Sprintf(
"%s.%d",
k.artID,
"%s-%s.%d",
k.artID.Kind,
k.artID.ID,
k.lastUpdate.UnixMilli(),
)
}