Remove dead code: duplicate ExternalRelease/Artist/ParsedArtist structs in model.go, ParseArtist/mbArtist/mbArtistData in client.go, ArtistTypeFilter and related filtering functions in api.go, SyncArtistDiscographyWithFilter in sync.go, and CacheStats/IsArtistCacheValid in cache.go. Fix bugs: SaveExternalRelease now stores NULL instead of empty string for zero CachedAt; sync upserts are now transactional with stale release cleanup; getCachedReleases returns int instead of *CacheStats; doGet uses url.Values for proper query encoding of MBID. Fix tests: removed duplicate TestRun_GracefulShutdown, removed dead code (_ = dbPath) from TestNewApp, fixed assertions in httptest handler goroutine to avoid data race, increased rate limiter timing tolerance, removed Client.Close() calls (no-op removed), fixed sync test cache expiry to use UPDATE instead of 0 TTL races. Fix formatting: cancel()}() formatting in main.go, error format string in sync.go.
20 lines
574 B
Go
20 lines
574 B
Go
package musicbrainz
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"naviwatcher/internal/database"
|
|
)
|
|
|
|
// 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) {
|
|
releases, err := database.GetExternalReleasesByArtistWithCache(db, artistID, ttl)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("get cached releases: %w", err)
|
|
}
|
|
return len(releases), nil
|
|
}
|