Skip to content

Commit

Permalink
Merge pull request #3093 from metabrainz/ansh/fix-similar-artist-redi…
Browse files Browse the repository at this point in the history
…rect

fix: Fetch Artist info for redirected MBIDs
  • Loading branch information
anshg1214 authored Jan 8, 2025
2 parents b030773 + 72058e4 commit 31a9324
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions listenbrainz/db/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def load_artists_from_mbids_with_redirects(mb_curs, mbids: Iterable[str]) -> lis
JOIN mbids m
ON a.gid = m.gid::UUID
"""
results = execute_values(mb_curs, query, [(mbid,) for mbid in mbids], fetch=True)
results = execute_values(mb_curs, query, [(mbid,) for mbid in redirected_mbids], fetch=True)
metadata_idx = {row["artist_mbid"]: row for row in results}

# Finally collate all the results, ensuring that we have one entry with original_recording_mbid for each input
Expand All @@ -32,15 +32,17 @@ def load_artists_from_mbids_with_redirects(mb_curs, mbids: Iterable[str]) -> lis
redirected_mbid = index.get(mbid, mbid)
if redirected_mbid not in metadata_idx:
item = {
"artist_mbid": mbid,
"artist_mbid": redirected_mbid,
"name": None,
"comment": None,
"type": None,
"gender": None
"gender": None,
"original_artist_mbid": mbid
}
else:
data = metadata_idx[redirected_mbid]
item = dict(data)
item["original_artist_mbid"] = mbid

output.append(item)

Expand Down
2 changes: 1 addition & 1 deletion listenbrainz/db/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ def get_artists(mb_curs, ts_curs, mbids, algorithm, count):

metadata = load_artists_from_mbids_with_redirects(mb_curs, similar_mbids)
for item in metadata:
item["score"] = score_idx.get(item["artist_mbid"])
item["score"] = score_idx.get(item["original_artist_mbid"])
item["reference_mbid"] = mbid_idx.get(item["artist_mbid"])
return metadata

0 comments on commit 31a9324

Please sign in to comment.