fix: catalog-songs artistName filter must restrict rows (fixes empty valuation catalogs)

SW
4mo ago
+12-3

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:

  • isCompleteSong fails 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 artistName is provided, inner-join song_artists/accounts so the filter restricts rows. A non-matching artist now returns 0 → 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 so artists is 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_artists and accounts when artistName is set; keep LEFT joins when not filtering.
    • Filter out null accounts so artists is never [null].
    • Prevents hidden songs and the null.name crash while keeping artist-less tracks visible with no filter.
  • Refactors

    • Prettier-format selectCatalogSongsWithArtists for consistency.