fix: address second code review findings
- Add context cancellation check between pagination pages in GetArtistReleaseGroups for responsive graceful shutdown during large discography fetches. - Eliminate double DB query on cache hit by having GetCachedReleases return []ExternalRelease directly instead of just a count, avoiding a redundant second query in SyncArtistDiscography. - Update cache_test.go to match new GetCachedReleases return type. - Format main.go (pre-existing whitespace issue).
This commit is contained in:
@@ -32,17 +32,17 @@ func SyncArtistDiscography(
|
||||
}
|
||||
|
||||
// Step 1: Check cache.
|
||||
cachedCount, err := GetCachedReleases(db, artistMBID, ttl)
|
||||
cachedReleases, err := GetCachedReleases(db, artistMBID, ttl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sync artist discography: cache check failed: %w", err)
|
||||
}
|
||||
|
||||
// Step 2: If we have cached data, return it.
|
||||
if cachedCount > 0 {
|
||||
if len(cachedReleases) > 0 {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, fmt.Errorf("sync artist discography: %w", err)
|
||||
}
|
||||
return database.GetExternalReleasesByArtistWithCache(db, artistMBID, ttl)
|
||||
return cachedReleases, nil
|
||||
}
|
||||
|
||||
// Step 3: Cache miss — fetch from MusicBrainz API.
|
||||
|
||||
Reference in New Issue
Block a user