fix: address third code review findings
- Prevent infinite pagination loop when API returns empty release groups page - Move NormalizeString regexes to package level to avoid recompilation on every call - Use UTC consistently for cached_at timestamps to avoid DST-related TTL skew
This commit is contained in:
@@ -30,7 +30,7 @@ func GetExternalRelease(db *DB, rgid string) (*ExternalRelease, error) {
|
||||
func SaveExternalRelease(db *DB, release *ExternalRelease) error {
|
||||
var cachedAt interface{}
|
||||
if !release.CachedAt.IsZero() {
|
||||
cachedAt = release.CachedAt.Format("2006-01-02 15:04:05")
|
||||
cachedAt = release.CachedAt.UTC().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
_, err := db.Conn().Exec(
|
||||
"INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
@@ -145,7 +145,7 @@ func CountExternalReleases(db *DB) (int, error) {
|
||||
// GetExternalReleasesByArtistWithCache returns cached external_release rows for a given artist_id
|
||||
// that are within the specified TTL.
|
||||
func GetExternalReleasesByArtistWithCache(db *DB, artistID string, ttl time.Duration) ([]ExternalRelease, error) {
|
||||
cutoff := time.Now().Add(-ttl)
|
||||
cutoff := time.Now().UTC().Add(-ttl)
|
||||
rows, err := db.Conn().Query(
|
||||
"SELECT rgid, artist_id, title, type, release_date, is_ignored, cached_at FROM external_releases WHERE artist_id = ? AND cached_at >= ?",
|
||||
artistID, cutoff.Format("2006-01-02 15:04:05"),
|
||||
|
||||
Reference in New Issue
Block a user