feat: fix NotifyOnce map key to use composite ArtistID+RGID

This commit is contained in:
2026-07-26 12:37:57 +03:00
parent 395a7f9b07
commit f697ebf2f5
4 changed files with 92 additions and 10 deletions

View File

@@ -61,13 +61,14 @@ func TouchArtistSynced(db DBer, artistID string, syncedAt time.Time) error {
func SaveArtistSettings(db *DB, settings *ArtistSettings) error {
_, err := db.Conn().Exec(`
INSERT INTO artist_settings (id, name, mbid, ignore_singles, ignore_compilations, monitored, last_synced)
VALUES (?, ?, ?, ?, ?, ?, (SELECT last_synced FROM artist_settings WHERE id = ?))
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
name = excluded.name,
mbid = COALESCE(excluded.mbid, artist_settings.mbid),
ignore_singles = excluded.ignore_singles,
ignore_compilations = excluded.ignore_compilations,
monitored = excluded.monitored
monitored = excluded.monitored,
last_synced = COALESCE(excluded.last_synced, artist_settings.last_synced)
`,
settings.ID, settings.Name, nullIfEmpty(settings.MBID), settings.IgnoreSingles, settings.IgnoreCompilations, settings.Monitored, settings.ID,
)
@@ -86,6 +87,15 @@ func nullIfEmpty(s string) interface{} {
return s
}
// nullIfEmptyTime returns nil for zero time so COALESCE-preserving columns
// (e.g. last_synced) keep their existing value when the caller supplies no new one.
func nullIfEmptyTime(t time.Time) interface{} {
if t.IsZero() {
return nil
}
return t
}
// GetAllArtistSettings returns all rows from artist_settings.
func GetAllArtistSettings(db *DB) ([]ArtistSettings, error) {
rows, err := db.Conn().Query(