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

@@ -161,3 +161,30 @@ name collisions.)
ignore/restore actions persist.
- **External**: ensure `config.yaml.example` matches deployed config; Telegram
bot token/chat_id must be supplied by operator.
## Follow-up fixes (post code review)
After the plan's Tasks 1-10 merged, a code review surfaced and fixed:
- **Duplicate notifications**: `SyncArtistDiscography` previously deleted
`notifications_sent` for the whole artist on every cache-miss re-sync, which
wiped "already notified" tracking and re-sent digests. Now only notifications
for releases that disappear are pruned, and surviving releases keep their sent
markers. Re-sync is FK-safe (uses `INSERT OR REPLACE` + `rgid NOT IN (…)`).
- **Empty-discography caching**: artists with zero MusicBrainz release groups
were never cached (a `0`-row result was treated as a cache miss), re-fetching
every cycle. Added `artist_settings.last_synced` (migration `009`) as the cache
freshness signal so empty discographies honor the TTL.
- **`main.run` wiring**: the Web UI server and Telegram notifier scheduler are
now constructed in `NewApp` and started as goroutines in `run()` (previously
only the sync loop ran).
- **Overlap guard**: `startPeriodicSync` now skips a tick while a previous sync
is still in flight (buffered `done` channel) so syncs never overlap.
- **`server.public_url` config**: added so Telegram digest links use an
externally-reachable origin instead of the bind `host:port` (which defaults to
`0.0.0.0`). `NewServerWithConfig` falls back to host:port only for a real host.
- **Web handlers**: artist detail page now uses `scanner.ScanArtist` (per-artist)
instead of a full `ScanAll`; removed the always-false `releaseIgnored` lookup
and dead `endsWith` helper; the configured fuzzy threshold is now threaded
through `Server`.
- **DB connection pooling**: `:memory:` databases now use `SetMaxOpenConns(1)`
so migrations and queries share one in-memory store (prevents "missing column"
errors under the connection pool).