fix: catalog-songs artistName filter must restrict rows (fixes empty valuation catalogs)
The bug (why valuation catalogs render empty)
A warm lead lands on /catalogs/{id}; the chat's useArtistCatalogSongs filters by the active sidebar artist and falls back to unfiltered only when the filtered query returns total_count === 0.
#681's LEFT join broke that filter. With song_artists/accounts LEFT-joined, a non-matching artistName .eq no longer drops rows — it just nulls the embed. So GET /api/catalogs/songs?...&artistName=<active artist> on a catalog by a different artist returns every row with artists: [null] and a non-zero count. The chat's fallback never fires (count ≠ 0), so:
isCompleteSongfails on the[null]artist → all songs hidden ("Found N songs", empty list)- the row renderer hits
null.name→Cannot read properties of null (reading 'name')crash on "show all"
This masks the now-complete data from #684 (artists) + #687 (notes).
Fix
- When
artistNameis provided, inner-joinsong_artists/accountsso the filter restricts rows. A non-matching artist now returns0→ the chat's existing fallback refetches the full catalog → songs render with their real artists. - When no
artistName, keep the LEFT join (api#681) so artist-less tracks still surface. - Defensive:
.filter(Boolean)the accounts soartistsis never[null].
Verification (preview, real DB)
Greg Mendez catalog ccf07c48 (23 complete songs):
artistName=Gatsby Grace(non-matching) → before: 23 with[null]; after: 0 → chat falls back.artistName=Greg Mendez(matching) → 23 with real artists.- no
artistName→ 23 with artists (LEFT preserved).
(Preview curl results in a follow-up comment.) Root-cause fix for recoupable/chat#1801.
🤖 Generated with Claude Code
Summary by cubic
Fixes empty catalogs and a row crash in chat by making the catalog songs artistName filter restrict rows.
-
Bug Fixes
- Inner-join
song_artistsandaccountswhenartistNameis set; keep LEFT joins when not filtering. - Filter out null accounts so
artistsis never[null]. - Prevents hidden songs and the
null.namecrash while keeping artist-less tracks visible with no filter.
- Inner-join
-
Refactors
- Prettier-format
selectCatalogSongsWithArtistsfor consistency.
- Prettier-format