feat: use local library cover art for search results

CoverArtProxy now checks three sources in order:
1. Local library (instant) — matches by album+artist name against
   the release_groups/cover_art tables. Albums the user already
   owns show their local cover art immediately.
2. Disk cache (instant) — previously fetched CAA thumbnails.
3. Cover Art Archive (network) — fetches and caches to disk.

Library index is built once on first access (sync.Once) from a
single SQL query joining release_groups → cover_art → artists.
Keyed by lowercased 'album\x00artist' for exact name matching.

GetThumbnail now takes (mbid, albumName, artistName) so the proxy
can check the library before falling back to CAA. Frontend passes
the album title and artist credit from the search result.
This commit is contained in:
2026-03-25 19:00:29 -04:00
parent d5f34f242f
commit 0761cff408
5 changed files with 113 additions and 34 deletions
+5 -5
View File
@@ -36,7 +36,7 @@ func NewExploreService(logger *slog.Logger, db *database.DB) *Service {
mb := NewMusicBrainzClient(cache, logger.WithGroup("musicbrainz"))
lb := NewListenBrainzClient(limiter, cache, logger.WithGroup("listenbrainz"))
index := NewSearchIndex(db, lb, logger.WithGroup("search-index"))
artProxy := NewCoverArtProxy(limiter)
artProxy := NewCoverArtProxy(db, limiter)
logger.Info("explore service created")
@@ -156,11 +156,11 @@ func (e *Service) CoverArtGroupURL(releaseGroupMBID string) string {
}
// GetThumbnail returns a base64 data URL for the release group's
// cover art. Cached locally on disk — first call fetches from
// the Cover Art Archive, subsequent calls are instant.
// cover art. Checks local library art first (by album+artist
// name), then disk cache, then Cover Art Archive.
// Returns "" if no cover art is available.
func (e *Service) GetThumbnail(releaseGroupMBID string) string {
return e.artProxy.GetThumbnail(releaseGroupMBID)
func (e *Service) GetThumbnail(releaseGroupMBID, albumName, artistName string) string {
return e.artProxy.GetThumbnail(releaseGroupMBID, albumName, artistName)
}
// Search concurrently queries MusicBrainz for artists, release