fix: address code review findings

- Store cached_at in canonical UTC layout so the cache TTL cutoff comparison is a valid time ordering (previously go-sqlite3 serialized time.Time as RFC3339, making the space-separated cutoff match only by ASCII accident; same-day expired entries were falsely served as fresh).

- Remove stale no-op scanner config keys (ignore_bootlegs, include_compilations) from config.yaml.example and docs; these fields were removed from ScannerConfig but left in configs, silently doing nothing.
This commit is contained in:
2026-07-19 20:01:26 +03:00
parent 0bee9b9b27
commit b21bf07208
5 changed files with 20 additions and 17 deletions

View File

@@ -9,6 +9,21 @@ import (
_ "github.com/mattn/go-sqlite3"
)
// utcLayout is the canonical layout for the cached_at column. go-sqlite3
// serializes a time.Time as RFC3339, which does not compare correctly against
// the space-separated cutoff used by the cache query. Storing this layout keeps
// the lexicographic comparison in GetExternalReleasesByArtistWithCache valid.
const utcLayout = "2006-01-02 15:04:05"
// FormatCachedAt renders a timestamp in the canonical UTC layout for storage.
// A zero time yields nil so the column is left NULL.
func FormatCachedAt(t time.Time) interface{} {
if t.IsZero() {
return nil
}
return t.UTC().Format(utcLayout)
}
// joinSecondaryTypes renders a slice of secondary types as a comma-separated
// string for storage in the secondary_types TEXT column (empty when none).
func joinSecondaryTypes(types []string) string {
@@ -54,10 +69,7 @@ func GetExternalRelease(db *DB, rgid string) (*ExternalRelease, error) {
// SaveExternalRelease inserts or replaces an external_release row.
func SaveExternalRelease(db *DB, release *ExternalRelease) error {
var cachedAt interface{}
if !release.CachedAt.IsZero() {
cachedAt = release.CachedAt
}
var cachedAt interface{} = FormatCachedAt(release.CachedAt)
_, err := db.Conn().Exec(
"INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
release.RGID, release.ArtistID, release.Title, release.Type, release.ReleaseDate, release.IsIgnored, cachedAt, joinSecondaryTypes(release.SecondaryTypes),
@@ -157,10 +169,9 @@ func SetReleaseIgnored(db *DB, rgid string, ignored bool) 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) {
// cached_at is a TEXT DATETIME column serialized by the driver in the
// "2006-01-02 15:04:05" UTC layout. Compare against an explicitly
// formatted cutoff string in the same layout so the lexicographic
// comparison does not depend on the driver's time serialization behavior.
// cached_at is stored in the "2006-01-02 15:04:05" UTC layout via
// FormatCachedAt. Compare against an explicitly formatted cutoff string in
// the same layout so the lexicographic comparison is a valid time ordering.
const layout = "2006-01-02 15:04:05"
cutoff := time.Now().UTC().Add(-ttl).Format(layout)
rows, err := db.Conn().Query(

View File

@@ -137,7 +137,7 @@ func SyncArtistDiscography(
if _, err := tx.Exec(
"INSERT INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
ext.RGID, ext.ArtistID, ext.Title, ext.Type, ext.ReleaseDate, ext.IsIgnored, ext.CachedAt,
ext.RGID, ext.ArtistID, ext.Title, ext.Type, ext.ReleaseDate, ext.IsIgnored, database.FormatCachedAt(ext.CachedAt),
); err != nil {
return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err)
}