fix(quick-10): add migration 5 and fix entity cache for composite album key

- Migration 5 rebuilds release_groups with UNIQUE(name, album_artist_credit_id)
- Drops and recreates track_metadata VIEW during table rebuild
- Temporarily disables FK checks for safe table rebuild
- Entity cache now keys by album name + artist credit ID
- Update tests to use composite cache keys
This commit is contained in:
2026-03-05 10:25:53 -05:00
parent 999ab967be
commit d43ba7bd0c
3 changed files with 208 additions and 5 deletions
+13 -3
View File
@@ -1261,8 +1261,18 @@ func (l *Library) resolveReleaseGroup(
return sql.NullInt64{}
}
// Build composite cache key: "albumName\x00artistCreditID"
// (or "albumName\x00-1" if no artist). This prevents albums
// with the same name by different artists from colliding.
artistID := int64(-1)
if albumArtistCreditID.Valid {
artistID = albumArtistCreditID.Int64
}
cacheKey := fmt.Sprintf("%s\x00%d", tags.Album, artistID)
// Check cache first.
if cached, ok := cache.releaseGroups[tags.Album]; ok {
if cached, ok := cache.releaseGroups[cacheKey]; ok {
// If the cached release group lacks cover art and we now
// have it, update it.
if coverArtID.Valid && !cached.CoverArtID.Valid {
@@ -1280,7 +1290,7 @@ func (l *Library) resolveReleaseGroup(
)
} else {
cached.CoverArtID = coverArtID
cache.releaseGroups[tags.Album] = cached
cache.releaseGroups[cacheKey] = cached
}
}
@@ -1321,7 +1331,7 @@ func (l *Library) resolveReleaseGroup(
}
}
cache.releaseGroups[tags.Album] = rg
cache.releaseGroups[cacheKey] = rg
return sql.NullInt64{Int64: rg.ID, Valid: true}
}