Skip to content

Fix work images and artwork precaching#1517

Merged
michaelherger merged 2 commits intoLMS-Community:public/9.2from
darrell-k:fix-work-images
Feb 26, 2026
Merged

Fix work images and artwork precaching#1517
michaelherger merged 2 commits intoLMS-Community:public/9.2from
darrell-k:fix-work-images

Conversation

@darrell-k
Copy link
Contributor

Ensure that only the image from the first track of a work-instance is used even when there are multiple images for the set of tracks making up the work-instance.

This can happen with embedded track images of different sizes, for example.

Signed-off-by: darrell-k <darrell@darrell.org.uk>
@darrell-k darrell-k mentioned this pull request Feb 23, 2026
Signed-off-by: darrell-k <darrell@darrell.org.uk>
@darrell-k
Copy link
Contributor Author

I'm about to push a change to Slim::Music::Artwork which may help with Frank's reported issue https://forums.lyrion.org/forum/developer-forums/developers/1812885-artwork-db-exploding#post1813186

Unlike Slim::Music::Artwork::updateStandaloneArtwork, the sql in Slim::Music::Artwork::precacheAllArtwork was not grouping by album, so whole albums might be ignored if they shared artwork with other albums, or even if different embedded artwork just happened to be the same size (I suppose that's possible!).

I also added logic to the order by in $sth_get_album_art so that any external artwork is preferred to that embedded in the first track.

There are still some differences between Slim::Music::Artwork::updateStandaloneArtwork and Slim::Music::Artwork::precacheAllArtwork eg sth_get_album_art isn't in the former. Should I work on bringing them into line??

@darrell-k darrell-k changed the title Fix work images Fix work images and artwork precaching Feb 24, 2026
WHERE tracks.album = ?
AND tracks.coverid IS NOT NULL
ORDER BY tracks.disc, tracks.tracknum
ORDER BY CASE WHEN CAST(CAST(tracks.cover AS INTEGER) AS TEXT) = tracks.cover THEN '1' ELSE '0' END, tracks.disc, tracks.tracknum
Copy link
Member

@michaelherger michaelherger Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prioritisation of external images would only work if the hash didn't happen to be an all numerical value, right? Is it worth the casting overhead? Did you measure the overhead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added logic to the order by in $sth_get_album_art so that any external artwork is preferred to that embedded in the first track.

In more detail: the double cast converts the column's value to numeric and then back to text. we then compare it to the original value and if they're equal, we know that the original value was an integer, ie the size of the embedded artwork rather than a path to the external image.

This is then enclosed in a CASE statement so as to return 1 if the artwork is embedded and 0 if it is external.

The whole thing is used as the first sort key so that an external image will always take priority over an embedded image.

The existing code just uses the first track's image even if it was embedded and there is also an album-level image in the album's folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I only saw your initial description after I posted... and then edited my comment to be more specific. And now I see that I confused cover and coverid...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run a quick test listing tracks using those orders on my Pi4, with about 22k tracks. Overhead is negligible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good. What do you say about further work to bring Slim::Music::Artwork::updateStandaloneArtwork and Slim::Music::Artwork::precacheAllArtwork into line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align how the two work? I'm all for that. But this PR started as a fix, which I believe should even go into 9.1. Further alignment might be beyond a stable scope. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might do and definitely this fix should go into 9.1. Leave it with me for now.

I'm actually having ideas about #1513 now I have studied Slim::Music::Artwork. I think that PR can be simplified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, shall we merge this one, and back port in a few if good?

And yes, #1513 needs some cleanup IMHO. There were some no-op changes and probably cruft left behind by the AI assistant forgetting what it had done before...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check whether the sth_get_album_art processing needs adding to Slim::Music::Artwork::updateStandaloneArtwork. I'm wondering if it needs to be for a album rescan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelherger Let's go with this as it is.

@michaelherger michaelherger merged commit 0fdd468 into LMS-Community:public/9.2 Feb 26, 2026
1 check passed
@michaelherger
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants