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"
PlaceholderAlbumArt = "placeholder.png"
PlaceholderAvatar = "logo-192x192.png"
DefaultUIVolume = 100
UICoverArtSize = 300
DefaultUIVolume = 100
DefaultHttpClientTimeOut = 10 * time.Second

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"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)
defer cancel()
r, _, err := a.artwork.Get(ctx, id, 0)
r, _, err := a.artwork.Get(ctx, id, consts.UICoverArtSize)
if err != nil {
return fmt.Errorf("error cacheing id='%s': %w", id, err)
}

View file

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

View file

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