A track credited to more than one artist has exactly one navigable artist in this app and the rest are punctuation. `primaryArtist()` string-parses the credit, strips a " feat. " clause and discards the guest; it deliberately does not split on "&", "with" or "," because those live inside real artist names. Measured on a real 26,069-file library plus an 80+80 MusicBrainz sample: 13% of recordings are multi-artist upstream, while only 0.86% of files carry any structured multi-artist tag — mp3 carries zero files with multiple MUSICBRAINZ_ARTISTID across 19,840. Of 1,286 files saying "feat.", 90% have nothing structured behind it, and a sample of 80 such files was multi-artist in MB 80 times out of 80. CLAUDE.md justified plan 013's removal of the credit tables with "3 credits of 2,823 listed more than one artist". That measured our own *writer* — cachedLinkArtist was called once per credit, so a collaboration could never have been recorded. Dropping the join table was still right on cost; the evidence for "multi-artist is rare" was not. A credit is ordered parts and the credit string is derived from them, so join phrases are assembly instructions, not disassembly ones. Nothing here reconstructs a credit by searching a name inside a credit string: the stored text may come from tags while the parts come from the catalog, and those disagree for ~1 in 3 multi-artist credits. Where it comes from, after two dead ends: the canonical dump CI already streams has no join phrases and no as-credited names, and the JSON dumps cover 153,691 recordings of ~35M with *zero* overlap against a real library. So mbdump.tar.bz2 — 7.1 GB, ~13.7 min in pure-Go bzip2, whose members are alphabetical, which is what lets one pass resolve an entity's credit without buffering 35M recordings. - artist_credit_part / artist_credit_ref, multi-artist credits only: a single-artist credit is already explore_index's own artist_name. - Column layouts verified against the real 20260815 export; ErrDumpShape makes a wrong guess a failed build, not a wrong catalog. - The pass runs on every mode, not just a build. The job picks its mode from the index's own state, and a complete import means "refresh", which never enters the importer — so credits could otherwise only arrive via a rebuild that re-downloads ~205 GB. It reports whether it populated anything, which is what flips `changed` and republishes. - The importer asks whether an artifact carries the tables, on the writer where `core` is attached, so the artifact already published still imports. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AfVYUVExXsx1nSWrXN8mAh
129 lines
3.5 KiB
Go
129 lines
3.5 KiB
Go
package explore
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"yellowjacket/backend/database"
|
|
)
|
|
|
|
// seedCredit writes one multi-artist credit and points an entity at it,
|
|
// the way the dump import and the artifact import both do.
|
|
func seedCredit(t *testing.T, db *database.DB, entity string, id int, parts []CreditPart) {
|
|
t.Helper()
|
|
|
|
pack := func(mbid string) []byte {
|
|
raw, err := hex.DecodeString(strings.ReplaceAll(mbid, "-", ""))
|
|
if err != nil || len(raw) != 16 {
|
|
t.Fatalf("bad fixture mbid %q: %v", mbid, err)
|
|
}
|
|
|
|
return raw
|
|
}
|
|
|
|
if _, err := db.ExecContext(
|
|
"INSERT INTO artist_credit_ref (mbid, credit_id) VALUES (?, ?)",
|
|
pack(entity), id,
|
|
); err != nil {
|
|
t.Fatalf("seed ref: %v", err)
|
|
}
|
|
|
|
for _, p := range parts {
|
|
if _, err := db.ExecContext(
|
|
`INSERT INTO artist_credit_part
|
|
(credit_id, position, artist_mbid, credited_name, join_phrase)
|
|
VALUES (?, ?, ?, ?, ?)`,
|
|
id, p.Position, pack(p.ArtistMBID), p.CreditedName, p.JoinPhrase,
|
|
); err != nil {
|
|
t.Fatalf("seed part: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGetCreditsDecomposes: the parts come back in position order and
|
|
// concatenate to the credit they describe.
|
|
func TestGetCreditsDecomposes(t *testing.T) {
|
|
db := database.NewTestDB(t)
|
|
si := NewSearchIndex(db, nil, nil, testLogger())
|
|
|
|
rec := testMBID("rec-1")
|
|
a, b := testMBID("artist-a"), testMBID("artist-b")
|
|
|
|
seedCredit(t, db, rec, 7, []CreditPart{
|
|
{Position: 0, ArtistMBID: a, CreditedName: "2Pac", JoinPhrase: " feat. "},
|
|
{Position: 1, ArtistMBID: b, CreditedName: "Snoop Dogg"},
|
|
})
|
|
|
|
got, err := si.GetCredits([]string{rec})
|
|
if err != nil {
|
|
t.Fatalf("GetCredits: %v", err)
|
|
}
|
|
|
|
parts := got[rec]
|
|
if len(parts) != 2 {
|
|
t.Fatalf("parts = %d, want 2", len(parts))
|
|
}
|
|
|
|
var rendered strings.Builder
|
|
for _, p := range parts {
|
|
rendered.WriteString(p.CreditedName)
|
|
rendered.WriteString(p.JoinPhrase)
|
|
}
|
|
|
|
if rendered.String() != "2Pac feat. Snoop Dogg" {
|
|
t.Errorf("rendered = %q, want %q", rendered.String(), "2Pac feat. Snoop Dogg")
|
|
}
|
|
|
|
// Dashed on the way out: a blob reaching the frontend is sixteen
|
|
// bytes of mojibake, and nothing above mbid.go speaks that.
|
|
if parts[0].ArtistMBID != a {
|
|
t.Errorf("artist mbid = %q, want %q", parts[0].ArtistMBID, a)
|
|
}
|
|
}
|
|
|
|
// TestGetCreditsOmitsSingleArtist: absence is the common case and means
|
|
// "nothing to decompose", so the caller renders its existing one link.
|
|
func TestGetCreditsOmitsSingleArtist(t *testing.T) {
|
|
db := database.NewTestDB(t)
|
|
si := NewSearchIndex(db, nil, nil, testLogger())
|
|
|
|
got, err := si.GetCredits([]string{testMBID("untagged"), ""})
|
|
if err != nil {
|
|
t.Fatalf("GetCredits: %v", err)
|
|
}
|
|
|
|
if len(got) != 0 {
|
|
t.Errorf("got %d credits, want none", len(got))
|
|
}
|
|
}
|
|
|
|
// TestGetCreditsBatches: the lookup is asked about whole tracklists, so
|
|
// it must not build one statement per row or one SQLite refuses to
|
|
// parse.
|
|
func TestGetCreditsBatches(t *testing.T) {
|
|
db := database.NewTestDB(t)
|
|
si := NewSearchIndex(db, nil, nil, testLogger())
|
|
|
|
mbids := make([]string, 0, creditLookupBatch*2+7)
|
|
for i := range creditLookupBatch*2 + 7 {
|
|
mbids = append(mbids, testMBID(fmt.Sprintf("batch-%d", i)))
|
|
}
|
|
|
|
// One real credit somewhere past the first batch boundary.
|
|
seedCredit(t, db, mbids[creditLookupBatch+3], 9, []CreditPart{
|
|
{Position: 0, ArtistMBID: testMBID("a"), CreditedName: "A", JoinPhrase: " & "},
|
|
{Position: 1, ArtistMBID: testMBID("b"), CreditedName: "B"},
|
|
})
|
|
|
|
got, err := si.GetCredits(mbids)
|
|
if err != nil {
|
|
t.Fatalf("GetCredits: %v", err)
|
|
}
|
|
|
|
if len(got[mbids[creditLookupBatch+3]]) != 2 {
|
|
t.Errorf("a credit past the first batch boundary was not returned")
|
|
}
|
|
}
|