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}
}
+5 -2
View File
@@ -533,7 +533,9 @@ func TestResolveReleaseGroup(t *testing.T) {
}
// Cover art should be updated on the cached release group.
cachedRG := cache.releaseGroups["A Night at the Opera"]
// Cache key is composite: "albumName\x00artistCreditID".
cacheKey := fmt.Sprintf("%s\x00%d", "A Night at the Opera", ac.ID)
cachedRG := cache.releaseGroups[cacheKey]
if !cachedRG.CoverArtID.Valid {
t.Error("expected CoverArtID to be set after update")
}
@@ -559,7 +561,8 @@ func TestResolveReleaseGroup_CacheHit(t *testing.T) {
q := lib.db.Queries
// Pre-populate cache with a known release group.
cache.releaseGroups["Cached Album"] = sqlcgen.ReleaseGroup{
// Cache key is composite: "albumName\x00artistCreditID" (use -1 for no artist).
cache.releaseGroups[fmt.Sprintf("%s\x00%d", "Cached Album", int64(-1))] = sqlcgen.ReleaseGroup{
ID: 42,
Name: "Cached Album",
}