musicbrainz-provider #2

Merged
Mrixs merged 72 commits from musicbrainz-provider into master 2026-08-05 20:19:16 +00:00
5 changed files with 20 additions and 17 deletions
Showing only changes of commit b21bf07208 - Show all commits

View File

@@ -94,8 +94,6 @@ telegram:
scanner: scanner:
fuzzy_threshold: 0.85 fuzzy_threshold: 0.85
ignore_bootlegs: true
include_compilations: true
``` ```
See [docs/Specification.md](docs/Specification.md) for the full configuration reference and architecture details. See [docs/Specification.md](docs/Specification.md) for the full configuration reference and architecture details.
@@ -206,8 +204,6 @@ telegram:
scanner: scanner:
fuzzy_threshold: 0.85 fuzzy_threshold: 0.85
ignore_bootlegs: true
include_compilations: true
``` ```
Полную справку по конфигурации и архитектуру см. в [docs/Specification.md](docs/Specification.md). Полную справку по конфигурации и архитектуру см. в [docs/Specification.md](docs/Specification.md).

View File

@@ -22,5 +22,3 @@ telegram:
scanner: scanner:
fuzzy_threshold: 0.85 fuzzy_threshold: 0.85
ignore_bootlegs: true
include_compilations: true

View File

@@ -147,8 +147,6 @@ telegram:
scanner: scanner:
fuzzy_threshold: 0.85 fuzzy_threshold: 0.85
ignore_bootlegs: true
include_compilations: true
``` ```

View File

@@ -9,6 +9,21 @@ import (
_ "github.com/mattn/go-sqlite3" _ "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 // joinSecondaryTypes renders a slice of secondary types as a comma-separated
// string for storage in the secondary_types TEXT column (empty when none). // string for storage in the secondary_types TEXT column (empty when none).
func joinSecondaryTypes(types []string) string { 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. // SaveExternalRelease inserts or replaces an external_release row.
func SaveExternalRelease(db *DB, release *ExternalRelease) error { func SaveExternalRelease(db *DB, release *ExternalRelease) error {
var cachedAt interface{} var cachedAt interface{} = FormatCachedAt(release.CachedAt)
if !release.CachedAt.IsZero() {
cachedAt = release.CachedAt
}
_, err := db.Conn().Exec( _, err := db.Conn().Exec(
"INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", "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), 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 // GetExternalReleasesByArtistWithCache returns cached external_release rows for a given artist_id
// that are within the specified TTL. // that are within the specified TTL.
func GetExternalReleasesByArtistWithCache(db *DB, artistID string, ttl time.Duration) ([]ExternalRelease, error) { func GetExternalReleasesByArtistWithCache(db *DB, artistID string, ttl time.Duration) ([]ExternalRelease, error) {
// cached_at is a TEXT DATETIME column serialized by the driver in the // cached_at is stored in the "2006-01-02 15:04:05" UTC layout via
// "2006-01-02 15:04:05" UTC layout. Compare against an explicitly // FormatCachedAt. Compare against an explicitly formatted cutoff string in
// formatted cutoff string in the same layout so the lexicographic // the same layout so the lexicographic comparison is a valid time ordering.
// comparison does not depend on the driver's time serialization behavior.
const layout = "2006-01-02 15:04:05" const layout = "2006-01-02 15:04:05"
cutoff := time.Now().UTC().Add(-ttl).Format(layout) cutoff := time.Now().UTC().Add(-ttl).Format(layout)
rows, err := db.Conn().Query( rows, err := db.Conn().Query(

View File

@@ -137,7 +137,7 @@ func SyncArtistDiscography(
if _, err := tx.Exec( if _, err := tx.Exec(
"INSERT INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at) VALUES (?, ?, ?, ?, ?, ?, ?)", "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 { ); err != nil {
return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err) return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err)
} }