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:
@@ -60,6 +60,12 @@ func (c *MusicBrainzClient) GetArtistReleaseGroups(ctx context.Context, artistMB
|
||||
if offset+len(parsed.ReleaseGroups) >= parsed.Count {
|
||||
break
|
||||
}
|
||||
|
||||
// Check context cancellation between pages for responsive shutdown.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, fmt.Errorf("fetch release groups for artist %s: %w", artistMBID, err)
|
||||
}
|
||||
|
||||
offset += limit
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user