diff --git a/build_disc_cache.py b/build_disc_cache.py index 2d9f672..ac3183c 100644 --- a/build_disc_cache.py +++ b/build_disc_cache.py @@ -20,9 +20,28 @@ def main(): rg.execute("TRUNCATE disc_cache") n = 0 for i in range(0, len(ids), 5000): + # artists_sort is NULL for most of this dump (~9.1M of 10.4M releases), and reading it + # alone silently cached a NULL artist — which is not merely a blank column in the admin + # list: dc.artist is also what the admin SEARCH and SORT run on, so an affected record + # becomes unfindable by artist name. Seen live on release 447087, cached as title + # "Mezcal" with no artist while its genre/style/label/country all populated, because + # those read disc_release_* and only the artist reads this cache. + # + # The name is in release_artist regardless. extra=0 is the RELEASE artist; extra=1 rows + # are credits — 447087 also lists Carl Clarke and Jim Eliot as Producers, and folding + # those into the artist name would be worse than leaving it blank. + # + # Comma-joined rather than reconstructing Discogs' join_string ("&", "Featuring"): this + # only fires where artists_sort is already NULL, and a predictable "A, B" beats both NULL + # and a dangling separator. rows = dg.execute( - "SELECT id, title, artists_sort, COALESCE(thumb_local_url, thumb), estimated_weight " - "FROM release WHERE id = ANY(%s)", (ids[i:i + 5000],)).fetchall() + "SELECT r.id, r.title, " + " COALESCE(r.artists_sort, (" + " SELECT string_agg(ra.artist_name, ', ' ORDER BY ra.position, ra.id) " + " FROM release_artist ra " + " WHERE ra.release_id = r.id AND ra.extra = 0)), " + " COALESCE(r.thumb_local_url, r.thumb), r.estimated_weight " + "FROM release r WHERE r.id = ANY(%s)", (ids[i:i + 5000],)).fetchall() with rg.cursor() as c: c.executemany( "INSERT INTO disc_cache (release_id, title, artist, thumb, weight) "