Implement better artwork cache keys
This commit is contained in:
@@ -21,12 +21,9 @@ type cacheKey struct {
|
|||||||
|
|
||||||
func (k *cacheKey) Key() string {
|
func (k *cacheKey) Key() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s.%d.%d.%d.%t",
|
"%s.%d",
|
||||||
k.artID.ID,
|
k.artID,
|
||||||
k.lastUpdate.UnixMilli(),
|
k.lastUpdate.UnixMilli(),
|
||||||
k.size,
|
|
||||||
conf.Server.CoverJpegQuality,
|
|
||||||
conf.Server.EnableMediaFileCoverArt,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package artwork
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -34,6 +36,18 @@ func newAlbumArtworkReader(ctx context.Context, artwork *artwork, artID model.Ar
|
|||||||
return a, nil
|
return 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 {
|
func (a *albumArtworkReader) LastUpdated() time.Time {
|
||||||
return a.album.UpdatedAt
|
return a.album.UpdatedAt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,13 +62,12 @@ func newArtistReader(ctx context.Context, artwork *artwork, artID model.ArtworkI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *artistReader) Key() string {
|
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(
|
return fmt.Sprintf(
|
||||||
"%s.%d.%d.%x",
|
"%s.%x.%t",
|
||||||
a.artID,
|
a.cacheKey.Key(),
|
||||||
a.lastUpdate.UnixMilli(),
|
hash,
|
||||||
a.size,
|
conf.Server.EnableExternalServices,
|
||||||
agentsHash,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package artwork
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/navidrome/navidrome/conf"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,6 +40,13 @@ func newMediafileArtworkReader(ctx context.Context, artwork *artwork, artID mode
|
|||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *mediafileArtworkReader) Key() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"%s.%t",
|
||||||
|
a.cacheKey.Key(),
|
||||||
|
conf.Server.EnableMediaFileCoverArt,
|
||||||
|
)
|
||||||
|
}
|
||||||
func (a *mediafileArtworkReader) LastUpdated() time.Time {
|
func (a *mediafileArtworkReader) LastUpdated() time.Time {
|
||||||
return a.lastUpdate
|
return a.lastUpdate
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ func resizedFromOriginal(ctx context.Context, a *artwork, artID model.ArtworkID,
|
|||||||
return r, nil
|
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 {
|
func (a *resizedArtworkReader) LastUpdated() time.Time {
|
||||||
return a.lastUpdate
|
return a.lastUpdate
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user