fix: address code review findings
- Start Web UI before the blocking initial sync so the dashboard is reachable during the (rate-limited, potentially multi-minute) first sync; fold the immediate sync into startPeriodicSync's overlap guard so it can never race a concurrent tick over the shared DB / MB client. - Make MarkNotificationSent idempotent: INSERT OR IGNORE for same-second PK collisions, and explicitly swallow FK violations when a release was pruned by a concurrent re-sync. Prevents a single vanished/duplicate release from aborting the digest mark-sent loop and re-sending. - Do not abort NotifyOnce's mark-sent loop on a single failure; log and continue so every release in the batch is marked. - NULL-safe reads: COALESCE(type,''), COALESCE(release_date,'') in the external_releases and unnotified readers to match the cache reader. - Update/extend tests for the new idempotency and startup contracts.
This commit is contained in:
@@ -52,7 +52,7 @@ func GetExternalRelease(db *DB, rgid string) (*ExternalRelease, error) {
|
||||
var cachedAt sql.NullTime
|
||||
var secondaryTypes sql.NullString
|
||||
err := db.Conn().QueryRow(
|
||||
"SELECT rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types FROM external_releases WHERE rgid = ?",
|
||||
"SELECT rgid, artist_id, title, COALESCE(type,''), COALESCE(release_date,''), is_ignored, cached_at, secondary_types FROM external_releases WHERE rgid = ?",
|
||||
rgid,
|
||||
).Scan(&r.RGID, &r.ArtistID, &r.Title, &r.Type, &r.ReleaseDate, &r.IsIgnored, &cachedAt, &secondaryTypes)
|
||||
if err != nil {
|
||||
@@ -83,7 +83,7 @@ func SaveExternalRelease(db *DB, release *ExternalRelease) error {
|
||||
// GetExternalReleasesByArtist returns all external_release rows for a given artist_id.
|
||||
func GetExternalReleasesByArtist(db *DB, artistID string) ([]ExternalRelease, error) {
|
||||
rows, err := db.Conn().Query(
|
||||
"SELECT rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types FROM external_releases WHERE artist_id = ?",
|
||||
"SELECT rgid, artist_id, title, COALESCE(type,''), COALESCE(release_date,''), is_ignored, cached_at, secondary_types FROM external_releases WHERE artist_id = ?",
|
||||
artistID,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -116,7 +116,7 @@ func GetExternalReleasesByArtist(db *DB, artistID string) ([]ExternalRelease, er
|
||||
// GetIgnoredReleases returns all external_release rows where is_ignored = 1.
|
||||
func GetIgnoredReleases(db *DB) ([]ExternalRelease, error) {
|
||||
rows, err := db.Conn().Query(
|
||||
"SELECT rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types FROM external_releases WHERE is_ignored = 1",
|
||||
"SELECT rgid, artist_id, title, COALESCE(type,''), COALESCE(release_date,''), is_ignored, cached_at, secondary_types FROM external_releases WHERE is_ignored = 1",
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query ignored releases: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user