From e89d99aee0e0f00e6448de6814d51a81d32ccd88 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 24 Dec 2022 16:21:49 -0500 Subject: [PATCH] Also caches resized images --- core/artwork.go | 22 +++++++++++----------- core/artwork_internal_test.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/artwork.go b/core/artwork.go index b6b1b0b7..a0db2d2f 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -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) diff --git a/core/artwork_internal_test.go b/core/artwork_internal_test.go index 725aa18c..3488c81a 100644 --- a/core/artwork_internal_test.go +++ b/core/artwork_internal_test.go @@ -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)