Also caches resized images

This commit is contained in:
Deluan 2022-12-24 16:21:49 -05:00 committed by Deluan Quintão
parent dc16ccdb93
commit e89d99aee0
2 changed files with 12 additions and 12 deletions

View File

@ -55,17 +55,6 @@ func (a *artwork) Get(ctx context.Context, id string, size int) (io.ReadCloser,
}
}
// If requested a resized image, get the original (possibly from cache)
if size > 0 && id != "" {
r, err := a.Get(ctx, id, 0)
if err != nil {
return nil, err
}
defer r.Close()
resized, err := a.resizedFromOriginal(ctx, artID, r, size)
return io.NopCloser(resized), err
}
key := &artworkKey{a: a, artID: artID, size: size}
r, err := a.cache.Get(ctx, key)
@ -85,6 +74,17 @@ func (f fromFunc) String() string {
}
func (a *artwork) get(ctx context.Context, artID model.ArtworkID, size int) (reader io.ReadCloser, path string, err error) {
// If requested a resized image, get the original (possibly from cache)
if size > 0 {
r, err := a.Get(ctx, artID.String(), 0)
if err != nil {
return nil, "", err
}
defer r.Close()
resized, err := a.resizedFromOriginal(ctx, artID, r, size)
return io.NopCloser(resized), fmt.Sprintf("%s@%d", artID, size), err
}
switch artID.Kind {
case model.KindAlbumArtwork:
reader, path = a.extractAlbumImage(ctx, artID)

View File

@ -183,7 +183,7 @@ var _ = Describe("Artwork", func() {
})
It("returns a JPEG if original image is not a PNG", func() {
conf.Server.CoverArtPriority = "cover.jpg"
r, err := aw.Get(context.Background(), alMultipleCovers.CoverArtID().String(), 200)
r, _, err := aw.get(context.Background(), alMultipleCovers.CoverArtID(), 200)
Expect(err).ToNot(HaveOccurred())
br, format, err := asImageReader(r)