Skip to content

perf: collapse useGroupVotes' three round-trips into one embedded-select query #168

Description

@chiptus

Problem

src/api/voting/useGroupVotes.ts:11-67 (fetchGroupVotes) does group_membersvotesprofiles as three sequential Supabase calls, manually joining in JS (profiles?.find((p) => p.id === vote.user_id)), instead of a single query with embedded resource selection (the pattern other src/api modules already use, e.g. sets embedding artists).

If the third profiles query errors, the error is only console.error'd and votes are still returned, with username: null for everyone — a silent partial-failure mode baked into the data-fetching layer.

Related but distinct from #161 (N+1 batching across 4 other call sites) — useGroupVotes.ts isn't in that ticket's list; this is a different shape of the same problem (sequential joins vs. per-row queries).

Fix

Replace the three-call manual join with one Supabase query using embedded votes(...)/profiles(...) selects. Let the query error propagate to the caller's error state instead of swallowing it.

Architecture note

Filed from an architecture review (module/interface/depth vocabulary, see /codebase-design).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions