Skip to content

perf: batch N+1 per-row Supabase queries into single .in() calls #161

Description

@chiptus

Problem

Four call sites fire one Supabase request per array item inside Promise.all(items.map(async ...)) instead of a single batched query:

  • src/api/groups/useUserGroups.ts:44-59 (addMemberCounts) — one count query per group.
  • src/api/groups/useGroupMembers.ts:25-41 — one profiles query per member.
  • src/api/admin-roles/useAdminRolesQuery.ts:23-36 — one profiles query per admin role.
  • src/pages/admin/Analytics/AnalyticsTable.tsx:45-57 and :71-83 — one count query per group and per user.

Fix

Replace with a single .in("id", ids) (or .in("group_id", ids) + client-side grouping via Map) call at each site. Same shape of fix everywhere; real latency win as groups/admins/users grow. Can be combined with the AnalyticsTable.tsxsrc/api/ refactor ticket since it touches the same file.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions