musicbrainz-provider #2
@@ -29,7 +29,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.UTC().Format("2006-01-02 15:04:05")
|
||||
cachedAt = release.CachedAt
|
||||
}
|
||||
_, err := db.Conn().Exec(
|
||||
"INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
@@ -125,7 +125,7 @@ func GetExternalReleasesByArtistWithCache(db *DB, artistID string, ttl time.Dura
|
||||
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"),
|
||||
artistID, cutoff,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query cached external releases: %w", err)
|
||||
|
||||
@@ -135,10 +135,9 @@ func SyncArtistDiscography(
|
||||
ext.IsIgnored = ignored
|
||||
}
|
||||
|
||||
cachedAtStr := ext.CachedAt.Format("2006-01-02 15:04:05")
|
||||
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, cachedAtStr,
|
||||
ext.RGID, ext.ArtistID, ext.Title, ext.Type, ext.ReleaseDate, ext.IsIgnored, ext.CachedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ func ScanAll(ctx context.Context, db *database.DB, threshold float64) ([]Missing
|
||||
}
|
||||
|
||||
var all []MissingRelease
|
||||
var failedArtists []string
|
||||
for _, s := range settings {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return all, err
|
||||
@@ -59,10 +60,15 @@ func ScanAll(ctx context.Context, db *database.DB, threshold float64) ([]Missing
|
||||
missing, err := ScanArtist(ctx, db, s.ID, threshold)
|
||||
if err != nil {
|
||||
log.Printf("scan artist %s failed: %v", s.ID, err)
|
||||
failedArtists = append(failedArtists, s.ID)
|
||||
continue
|
||||
}
|
||||
all = append(all, missing...)
|
||||
}
|
||||
|
||||
if n := len(failedArtists); n > 0 {
|
||||
log.Printf("scan completed with %d artist(s) skipped due to errors: %v", n, failedArtists)
|
||||
}
|
||||
|
||||
return all, nil
|
||||
}
|
||||
|
||||
@@ -59,7 +59,10 @@ func Similarity(a, b string) float64 {
|
||||
}
|
||||
|
||||
// IsMatch reports whether a and b are similar enough to be considered the
|
||||
// same release, given the provided threshold in [0.0, 1.0].
|
||||
// same release, given the provided threshold in [0.0, 1.0]. A threshold of 0
|
||||
// (unset) falls back to DefaultThreshold, so this primitive honors the same
|
||||
// zero-means-default contract as FindMissingReleases/ScanArtist/ScanAll rather
|
||||
// than treating 0 as "always match".
|
||||
func IsMatch(a, b string, threshold float64) bool {
|
||||
return Similarity(a, b) >= threshold
|
||||
return Similarity(a, b) >= resolveThreshold(threshold)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user