perf: batch artist image loading for library grid view

Replace per-artist sequential GetArtistMBID + GetArtistImageURL
calls (2 Wails round-trips × N artists) with a single batch
GetArtistImages(names[]) call that:

1. Resolves all names → MBIDs via AllArtistMBIDs() (one DB query)
2. Checks disk cache for each MBID via GetCachedImage (no network)
3. Returns map[name]→dataURL in one Wails bridge round-trip

Only returns already-cached images from the disk cache populated
by the index build. No network fetches triggered — artists whose
images haven't been cached yet keep the initial letter fallback
until the index build resolves them in the background.

Result: all cached artist images appear simultaneously on first
render instead of loading one-by-one over several seconds.
This commit is contained in:
2026-03-28 15:22:22 -04:00
parent df1d1785e9
commit 7ec9785463
5 changed files with 113 additions and 17 deletions
+10
View File
@@ -76,6 +76,16 @@ func NewArtistImageProvider(
}
}
// GetCachedImage returns a base64 data URL from the disk cache
// only — no network fetches. Returns "" if not cached.
func (p *ArtistImageProvider) GetCachedImage(artistMBID string) string {
if artistMBID == "" || p.imageDir == "" {
return ""
}
return p.readDiskCache(artistMBID)
}
// GetArtistImage returns a base64 data URL for the artist's photo.
// Checks disk cache first, then resolves via MB/Wikidata and fetches
// the image from Wikimedia Commons. Returns "" if no image.
+26
View File
@@ -233,6 +233,32 @@ func (e *Service) GetArtistMBID(artistName string) string {
return e.libMBID.GetArtistMBID(artistName)
}
// GetArtistImages resolves artist images for multiple artists by
// name in one call. Returns a map of artist name → base64 data
// URL. Only artists with cached images are returned — no network
// fetches are triggered (use GetArtistImageURL for on-demand fetch).
func (e *Service) GetArtistImages(names []string) map[string]string {
result := make(map[string]string, len(names))
// Batch resolve all names → MBIDs from the library DB.
allMBIDs := e.libMBID.AllArtistMBIDs()
for _, name := range names {
mbid, ok := allMBIDs[name]
if !ok || mbid == "" {
continue
}
// Only return already-cached images — don't trigger fetches.
img := e.artistImg.GetCachedImage(mbid)
if img != "" {
result[name] = img
}
}
return result
}
// Search concurrently queries MusicBrainz for artists, release
// groups, and recordings matching the query, then boosts results
// using ListenBrainz popularity data. The final score blends