Repository navigation
Fix admin members API N+1 query and extract to dedicated module - #510
Merged
Merged
Conversation
- Replace N+1 WorkOS API calls with efficient SQL using LEFT JOIN LATERAL to get member emails from local organization_memberships table - Move 5 members-related routes from http.ts to new members.ts module: - GET /api/admin/members (list all members) - POST /api/admin/members/:orgId/sync (sync from WorkOS/Stripe) - PATCH /api/admin/members/:orgId/memberships/:membershipId (update role) - GET /api/admin/members/:orgId/payments (payment history) - DELETE /api/admin/members/:orgId (delete workspace) - Reduces http.ts by ~456 lines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LEFT JOIN LATERALto get member emails from localorganization_membershipstableserver/src/routes/admin/members.tsmoduleProblem
The
/api/admin/membersendpoint was making N+1 WorkOS API calls - onelistOrganizationMemberships()and onegetUser()call for every organization. With hundreds of organizations, this caused timeouts and "Load failed" errors in production.Solution
Use efficient SQL with
LEFT JOIN LATERALto get the first member email from the localorganization_membershipstable (which is synced from WorkOS via webhooks). This replaces potentially hundreds of API calls with a single database query.Routes Moved
GET /api/admin/members- List all members with subscription infoPOST /api/admin/members/:orgId/sync- Sync from WorkOS/StripePATCH /api/admin/members/:orgId/memberships/:membershipId- Update membership roleGET /api/admin/members/:orgId/payments- Get payment historyDELETE /api/admin/members/:orgId- Delete workspaceTest plan
🤖 Generated with Claude Code