fix: address code review findings

- Fix duplicate Telegram notifications: SyncArtistDiscography no longer wipes
  notifications_sent for the whole artist on every cache-miss re-sync; only
  markers for releases that disappear are pruned (FK-safe via INSERT OR REPLACE
  + rgid NOT IN (...)).
- Cache empty MusicBrainz discographies via a new artist_settings.last_synced
  column (migration 009) so zero-release artists honor the TTL instead of being
  re-fetched every cycle.
- Wire the Web UI server and Telegram notifier scheduler into main.run/NewApp.
- Guard startPeriodicSync against overlapping syncs with a done-channel slot.
- Add server.public_url config; NewServerWithConfig derives reachable links
  and no longer advertises the 0.0.0.0 bind address.
- Web handlers: use scanner.ScanArtist per artist, drop always-false
  releaseIgnored lookup and dead endsWith, thread configured threshold.
- Limit :memory: DB pool to one connection so migrations and queries share the
  same in-memory store.
This commit is contained in:
2026-07-19 23:38:33 +03:00
parent e493a4d228
commit 389d177d85
15 changed files with 386 additions and 126 deletions

View File

@@ -166,6 +166,42 @@ func SetReleaseIgnored(db *DB, rgid string, ignored bool) error {
return nil
}
// ArtistCacheFresh reports whether the artist was synced within the TTL. A hit
// requires a fresh external_releases row (covers pre-seeded/non-empty caches)
// OR a fresh artist_settings.last_synced (covers empty discographies, which
// store no external_releases rows but are still marked as synced). Either
// signal means we should not re-fetch from MusicBrainz.
func ArtistCacheFresh(db *DB, artistID string, ttl time.Duration) (bool, error) {
if ttl <= 0 {
return false, nil
}
cutoff := time.Now().UTC().Add(-ttl).Format(utcLayout)
var dummy int
err := db.Conn().QueryRow(
"SELECT 1 FROM external_releases WHERE artist_id = ? AND cached_at >= ? LIMIT 1",
artistID, cutoff,
).Scan(&dummy)
if err == nil {
return true, nil
}
if err != sql.ErrNoRows {
return false, fmt.Errorf("check artist cache freshness (releases): %w", err)
}
// Fall back to the per-artist last_synced marker (set even on empty syncs).
err = db.Conn().QueryRow(
"SELECT 1 FROM artist_settings WHERE id = ? AND last_synced >= ? LIMIT 1",
artistID, cutoff,
).Scan(&dummy)
if err == nil {
return true, nil
}
if err == sql.ErrNoRows {
return false, nil
}
return false, fmt.Errorf("check artist cache freshness (settings): %w", err)
}
// 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) {