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:
2026-05-26 15:58:40 +03:00
parent 2baf586607
commit 582202bb86
5 changed files with 34 additions and 25 deletions

View File

@@ -9,11 +9,11 @@ import (
// GetCachedReleases queries the external_releases table for entries
// belonging to the given artist that were cached within the specified TTL.
// It returns the count of cached entries and any error encountered.
func GetCachedReleases(db *database.DB, artistID string, ttl time.Duration) (int, error) {
// It returns the cached releases and any error encountered.
func GetCachedReleases(db *database.DB, artistID string, ttl time.Duration) ([]database.ExternalRelease, error) {
releases, err := database.GetExternalReleasesByArtistWithCache(db, artistID, ttl)
if err != nil {
return 0, fmt.Errorf("get cached releases: %w", err)
return nil, fmt.Errorf("get cached releases: %w", err)
}
return len(releases), nil
return releases, nil
}