fix: address code review findings

- Honor ignore_singles/ignore_compilations at scanner read time so toggles
  take effect immediately on the dashboard, artist page, and digest instead
  of waiting for the MusicBrainz cache to expire and prune rows.
- Run notifier notify synchronously in the scheduler loop to avoid overlapping
  read-send-mark runs double-sending the digest.
- Show artist name (with ID fallback) on the archive page instead of raw IDs.
- Select last_synced in GetAllArtistSettings for contract consistency.
- Fix stale startPeriodicSync comment and remove redundant error var.
- Remove dead ignored-branch from the artist template (never rendered).
- Add tests: CSRF sameOrigin, ArtistCacheFresh, secondary_types round-trip,
  and scanner type-toggle filtering.
- Update Specification.md schema/config to reflect mbid, last_synced,
  secondary_types, sync.interval, and server.public_url.
This commit is contained in:
2026-07-20 06:18:21 +03:00
parent f5b0034b4d
commit a8aa445d94
13 changed files with 402 additions and 31 deletions

View File

@@ -246,3 +246,61 @@ func seedArtistUnmonitored(t *testing.T, db *database.DB, id, name string) {
t.Fatalf("seedArtistUnmonitored(%s) error: %v", id, err)
}
}
// TestScanArtist_TypeToggle verifies that ScanArtist honors the artist's
// ignore_singles / ignore_compilations toggles at read time, so a toggled
// artist stops reporting those categories as missing immediately (without
// waiting for the MusicBrainz cache to expire).
func TestScanArtist_TypeToggle(t *testing.T) {
db := newTestDB(t)
defer db.Close()
seedArtist(t, db, "a1", "Artist")
seedExternalRelease(t, db, "rg-album", "a1", "Album", false)
seedExternalRelease(t, db, "rg-single", "a1", "Single", false)
// seedExternalRelease leaves Type empty; set the primary type that the
// toggle filtering keys on.
if _, err := db.Conn().Exec("UPDATE external_releases SET type = ? WHERE rgid = ?", "Album", "rg-album"); err != nil {
t.Fatalf("set album type: %v", err)
}
if _, err := db.Conn().Exec("UPDATE external_releases SET type = ? WHERE rgid = ?", "Single", "rg-single"); err != nil {
t.Fatalf("set single type: %v", err)
}
// No toggle: both reported missing (no local albums).
got, err := ScanArtist(context.Background(), db, "a1", 0)
if err != nil {
t.Fatalf("ScanArtist error: %v", err)
}
if len(got) != 2 {
t.Fatalf("expected 2 missing before toggle, got %d", len(got))
}
// Toggle ignore_singles on.
if err := database.UpdateArtistSettings(db, "a1", map[string]interface{}{"ignore_singles": true}); err != nil {
t.Fatalf("toggle ignore_singles: %v", err)
}
got, err = ScanArtist(context.Background(), db, "a1", 0)
if err != nil {
t.Fatalf("ScanArtist error: %v", err)
}
if len(got) != 1 || got[0].RGID != "rg-album" {
ids := make([]string, len(got))
for i, m := range got {
ids[i] = m.RGID
}
t.Fatalf("expected only rg-album after toggle, got %v", ids)
}
// Toggle back off: single reappears.
if err := database.UpdateArtistSettings(db, "a1", map[string]interface{}{"ignore_singles": false}); err != nil {
t.Fatalf("toggle ignore_singles off: %v", err)
}
got, err = ScanArtist(context.Background(), db, "a1", 0)
if err != nil {
t.Fatalf("ScanArtist error: %v", err)
}
if len(got) != 2 {
t.Fatalf("expected 2 missing after toggle off, got %d", len(got))
}
}