feat: add get_artist_fans RPC for paginated fan lookup
Closed
AR
7mo ago+69+69+01234567890123456789-0-0-0123456789
Summary
- Adds
public.get_artist_fans(artist_account_id uuid, limit_count int, offset_count int)which joinsartist_segments->fan_segments->socials, DISTINCT-onsocials.id, orders byupdated_at DESC NULLS LAST, id, and paginates in-database. - Returns the 9-field socials projection plus
total_countviaCOUNT(*) OVER(), repeated on each row (callers read from the first row). - Replaces the api-side composer that fetched every
fan_social_idinto memory and sliced — that approach silently truncated above Supabase's implicit 10,000-row ceiling for popular artists.
Why
The api route GET /api/artists/{id}/fans currently composes three round-trips and a memory-side dedupe+slice. Pushing DISTINCT/ORDER/LIMIT/OFFSET into Postgres removes the row ceiling, cuts wire volume, and lets existing indexes (idx_artist_segments_artist_account_id, idx_fan_segments_segment_id, idx_fan_segments_fan_social_id, socials PK) do the work.
Notes
STABLE LANGUAGE sql. No RLS onartist_segments,fan_segments, orsocialstoday, so the function inherits current access semantics.- Envelope/shape matches the api response byte-for-byte; no api-surface change.
- Response envelope produced by the api caller stays identical:
{ status, fans, pagination: { total_count, page, limit, total_pages } }.
Test plan
- Apply migration to the dev Supabase instance.
- Smoke:
select * from get_artist_fans('<artist uuid>', 20, 0);returns rows withtotal_countcolumn matching a manualCOUNT(DISTINCT fan_social_id). - Verify api PR recoupable/api#453 against preview once migration is applied.
Deploy ordering
Must land and be applied to the Supabase instance before recoupable/api#453.
Summary by cubic
Adds a Postgres RPC to fetch an artist’s fans with in-database dedupe, ordering, and pagination, replacing the API-side composer. This removes the 10k-row ceiling for popular artists and cuts round-trips.
-
New Features
- New
public.get_artist_fans(artist_account_id uuid, limit int, offset int)joiningartist_segments→fan_segments→socials. - Uses DISTINCT on
socials.id, orders byupdated_at DESC NULLS LAST, id, and paginates in DB. - Returns the socials projection plus
total_countviaCOUNT(*) OVER(); API response shape remains unchanged.
- New
-
Migration
- Apply the Supabase migration before
recoupable/api#453. - Smoke test:
select * from public.get_artist_fans('<artist-uuid>', 20, 0);and verifytotal_count.
- Apply the Supabase migration before