Fix resized image cache key

This commit is contained in:
Deluan 2023-01-17 20:58:38 -05:00
parent bedd2b2074
commit 17eab6a88d
4 changed files with 15 additions and 11 deletions

View file

@ -57,8 +57,8 @@ const (
PlaceholderArtistArt = "artist-placeholder.webp" PlaceholderArtistArt = "artist-placeholder.webp"
PlaceholderAlbumArt = "placeholder.png" PlaceholderAlbumArt = "placeholder.png"
PlaceholderAvatar = "logo-192x192.png" PlaceholderAvatar = "logo-192x192.png"
UICoverArtSize = 300
DefaultUIVolume = 100 DefaultUIVolume = 100
DefaultHttpClientTimeOut = 10 * time.Second DefaultHttpClientTimeOut = 10 * time.Second

View file

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request" "github.com/navidrome/navidrome/model/request"
@ -106,7 +107,7 @@ func (a *cacheWarmer) doCacheImage(ctx context.Context, id string) error {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second) ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel() defer cancel()
r, _, err := a.artwork.Get(ctx, id, 0) r, _, err := a.artwork.Get(ctx, id, consts.UICoverArtSize)
if err != nil { if err != nil {
return fmt.Errorf("error cacheing id='%s': %w", id, err) return fmt.Errorf("error cacheing id='%s': %w", id, err)
} }

View file

@ -15,7 +15,6 @@ import (
type cacheKey struct { type cacheKey struct {
artID model.ArtworkID artID model.ArtworkID
size int
lastUpdate time.Time lastUpdate time.Time
} }

View file

@ -20,28 +20,32 @@ import (
) )
type resizedArtworkReader struct { type resizedArtworkReader struct {
cacheKey artID model.ArtworkID
a *artwork cacheKey string
lastUpdate time.Time
size int
a *artwork
} }
func resizedFromOriginal(ctx context.Context, a *artwork, artID model.ArtworkID, size int) (*resizedArtworkReader, error) { func resizedFromOriginal(ctx context.Context, a *artwork, artID model.ArtworkID, size int) (*resizedArtworkReader, error) {
r := &resizedArtworkReader{a: a} r := &resizedArtworkReader{a: a}
r.cacheKey.artID = artID r.artID = artID
r.cacheKey.size = size r.size = size
// Get lastUpdated from original artwork // Get lastUpdated and cacheKey from original artwork
original, err := a.getArtworkReader(ctx, artID, 0) original, err := a.getArtworkReader(ctx, artID, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
r.cacheKey.lastUpdate = original.LastUpdated() r.cacheKey = original.Key()
r.lastUpdate = original.LastUpdated()
return r, nil return r, nil
} }
func (a *resizedArtworkReader) Key() string { func (a *resizedArtworkReader) Key() string {
return fmt.Sprintf( return fmt.Sprintf(
"%s.%d.%d", "%s.%d.%d",
a.cacheKey.Key(), a.cacheKey,
a.size, a.size,
conf.Server.CoverJpegQuality, conf.Server.CoverJpegQuality,
) )