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:
2026-07-20 06:27:42 +03:00
parent a8aa445d94
commit aee0241bb7
6 changed files with 110 additions and 42 deletions

View File

@@ -143,8 +143,10 @@ func TestStartPeriodicSync_CancelsCleanly(t *testing.T) {
close(done)
}()
// With a 1h interval the ticker would never fire on its own; cancel should
// return promptly.
// With a 1h interval the ticker never fires on its own; cancel should
// return promptly. The loop does run one immediate (guarded) sync at
// startup, so depending on scheduling calls may be 0 (cancel won the race)
// or 1 (immediate sync ran) — but never more, since no tick can fire in 1h.
cancel()
select {
@@ -154,8 +156,8 @@ func TestStartPeriodicSync_CancelsCleanly(t *testing.T) {
t.Fatal("startPeriodicSync did not exit after ctx cancellation")
}
if got := atomic.LoadInt64(&calls); got != 0 {
t.Errorf("expected no sync calls with 1h interval, got %d", got)
if got := atomic.LoadInt64(&calls); got > 1 {
t.Errorf("expected at most 1 (immediate) sync call with 1h interval, got %d", got)
}
}