🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Implement better artwork cache keys
Deluanbedd2b20745d
diff --git a/core/artwork/image_cache.go b/core/artwork/image_cache.goindex 13c8b8fdd..524ca7b38 100644--- a/core/artwork/image_cache.go+++ b/core/artwork/image_cache.go@@ -21,12 +21,9 @@ type cacheKey struct {func (k *cacheKey) Key() string {return fmt.Sprintf(- "%s.%d.%d.%d.%t",- k.artID.ID,+ "%s.%d",+ k.artID,k.lastUpdate.UnixMilli(),- k.size,- conf.Server.CoverJpegQuality,- conf.Server.EnableMediaFileCoverArt,)}diff --git a/core/artwork/reader_album.go b/core/artwork/reader_album.goindex 54174e653..8d3ce5db0 100644--- a/core/artwork/reader_album.go+++ b/core/artwork/reader_album.go@@ -2,6 +2,8 @@ package artworkimport ("context"+ "crypto/md5"+ "fmt""io""strings""time"@@ -34,6 +36,18 @@ func newAlbumArtworkReader(ctx context.Context, artwork *artwork, artID model.Arreturn a, nil}+func (a *albumArtworkReader) Key() string {+ var hash [16]byte+ if conf.Server.EnableExternalServices {+ hash = md5.Sum([]byte(conf.Server.Agents + conf.Server.CoverArtPriority))+ }+ return fmt.Sprintf(+ "%s.%x.%t",+ a.cacheKey.Key(),+ hash,+ conf.Server.EnableExternalServices,+ )+}func (a *albumArtworkReader) LastUpdated() time.Time {return a.album.UpdatedAt}diff --git a/core/artwork/reader_artist.go b/core/artwork/reader_artist.goindex 6464779fe..bb02ccf21 100644--- a/core/artwork/reader_artist.go+++ b/core/artwork/reader_artist.go@@ -62,13 +62,12 @@ func newArtistReader(ctx context.Context, artwork *artwork, artID model.ArtworkI}func (a *artistReader) Key() string {- agentsHash := md5.Sum([]byte(conf.Server.Agents + conf.Server.Spotify.ID))+ hash := md5.Sum([]byte(conf.Server.Agents + conf.Server.Spotify.ID))return fmt.Sprintf(- "%s.%d.%d.%x",- a.artID,- a.lastUpdate.UnixMilli(),- a.size,- agentsHash,+ "%s.%x.%t",+ a.cacheKey.Key(),+ hash,+ conf.Server.EnableExternalServices,)}diff --git a/core/artwork/reader_mediafile.go b/core/artwork/reader_mediafile.goindex 15e06250c..b86fe7154 100644--- a/core/artwork/reader_mediafile.go+++ b/core/artwork/reader_mediafile.go@@ -2,9 +2,11 @@ package artworkimport ("context"+ "fmt""io""time"+ "github.com/navidrome/navidrome/conf""github.com/navidrome/navidrome/model")@@ -38,6 +40,13 @@ func newMediafileArtworkReader(ctx context.Context, artwork *artwork, artID modereturn a, nil}+func (a *mediafileArtworkReader) Key() string {+ return fmt.Sprintf(+ "%s.%t",+ a.cacheKey.Key(),+ conf.Server.EnableMediaFileCoverArt,+ )+}func (a *mediafileArtworkReader) LastUpdated() time.Time {return a.lastUpdate}diff --git a/core/artwork/reader_resized.go b/core/artwork/reader_resized.goindex 61bb9c056..be0066596 100644--- a/core/artwork/reader_resized.go+++ b/core/artwork/reader_resized.go@@ -38,6 +38,15 @@ func resizedFromOriginal(ctx context.Context, a *artwork, artID model.ArtworkID,return r, nil}+func (a *resizedArtworkReader) Key() string {+ return fmt.Sprintf(+ "%s.%d.%d",+ a.cacheKey.Key(),+ a.size,+ conf.Server.CoverJpegQuality,+ )+}+func (a *resizedArtworkReader) LastUpdated() time.Time {return a.lastUpdate}