feat(library): match own-state on artist MBID, not just name
Own-state ("in library") relied on an exact artist-NAME match, so an owned
album whose name differed from the MB canonical (punctuation/locale/feat.)
showed as not-owned even when followed. Capture the MusicBrainz artist MBID
on LibraryItem and prefer it for matching.
- New LibraryItem.artistMbid (migration add_library_artist_mbid). Populated at
import (pipeline) + scan, both of which already hold the resolved target;
the pipeline also now stores rgMbid (it previously didn't). COALESCE on
conflict backfills MBIDs on re-scan without clobbering.
- /api/artists "in library, not followed" matches by artistMbid first, name
case-insensitively as fallback (rows predating the column). Library route
prefers the item's own artistMbid over the release join.
Last.fm/discover own-state still use name-match (they work) — a smaller
follow-up. worker 233, web 186 tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,16 @@ describe("artists collection API", () => {
|
||||
expect(body.ownedNotFollowed).not.toContain("followed artist"); // case-insensitive match
|
||||
});
|
||||
|
||||
it("GET matches owned artists to the watched roster by MBID despite a name mismatch", async () => {
|
||||
// followed under the canonical MB name, but the library row's name differs (feat./locale)
|
||||
await prisma.watchedArtist.create({ data: { mbid: "mb-beyonce", name: "Beyoncé" } });
|
||||
await prisma.libraryItem.create({
|
||||
data: { artist: "Beyonce", album: "Lemonade", artistMbid: "mb-beyonce", path: "/l", source: "scan", format: "FLAC", qualityClass: 2 },
|
||||
});
|
||||
const body = await (await GET(listReq())).json();
|
||||
expect(body.ownedNotFollowed).not.toContain("Beyonce"); // matched by MBID → not "unfollowed"
|
||||
});
|
||||
|
||||
it("GET ?mbid= returns the follow state for a single artist", async () => {
|
||||
await prisma.watchedArtist.create({ data: { mbid: "followed-1", name: "Followed" } });
|
||||
expect((await (await GET(listReq("?mbid=followed-1"))).json()).followed).toBe(true);
|
||||
|
||||
@@ -20,16 +20,21 @@ export async function GET(request: Request) {
|
||||
},
|
||||
},
|
||||
}),
|
||||
prisma.libraryItem.findMany({ select: { artist: true }, distinct: ["artist"] }),
|
||||
prisma.libraryItem.findMany({ select: { artist: true, artistMbid: true } }),
|
||||
]);
|
||||
|
||||
// Artists you own music by (LibraryItem) but don't follow yet — name-matched
|
||||
// case-insensitively against the watched roster (the have-via-scan name-match caveat).
|
||||
// Artists you own music by (LibraryItem) but don't follow yet. Match on the MusicBrainz
|
||||
// ARTIST MBID first (robust to name punctuation/locale/feat. variants), falling back to a
|
||||
// case-insensitive name match for library rows that predate the artistMbid column.
|
||||
const followedMbids = new Set(artists.map((a) => a.mbid));
|
||||
const followedNames = new Set(artists.map((a) => a.name.trim().toLowerCase()));
|
||||
const ownedNotFollowed = libraryArtists
|
||||
.map((r) => r.artist)
|
||||
.filter((name) => name.trim() && !followedNames.has(name.trim().toLowerCase()))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
const isFollowed = (r: { artist: string; artistMbid: string | null }) =>
|
||||
(r.artistMbid && followedMbids.has(r.artistMbid)) || followedNames.has(r.artist.trim().toLowerCase());
|
||||
const ownedNotFollowed = [
|
||||
...new Set(
|
||||
libraryArtists.filter((r) => r.artist.trim() && !isFollowed(r)).map((r) => r.artist),
|
||||
),
|
||||
].sort((a, b) => a.localeCompare(b));
|
||||
|
||||
return Response.json({
|
||||
artists: artists.map((a) => {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user