Repository navigation
OUT-4208: collapse duplicate custom-fields requests on client pageload - #238
Conversation
…geload The /client pageload fired two parallel GET /api/custom-fields/[entityType] requests (client + company), which Sentry's N+1 API Call detector groups and flags. Fetch all entity types in a single GET /api/custom-fields and split them client-side by entityType, removing the now-unused dynamic route. Fixes CLIENT-HOME-V3-1X Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
| const { data: customFields, isLoading: fieldsIsLoading } = useQuery({ | ||
| queryKey: [CUSTOM_FIELDS_QUERY_KEY], | ||
| queryFn: async (): Promise<CustomFieldItemWithEntity[]> => { | ||
| const res = await api.get('/api/custom-fields') |
There was a problem hiding this comment.
There is no automated test for the new one-request path or its client/company split. Add a hook test that mocks a mixed, unordered response and asserts one
GET /api/custom-fields, two ordered lists, and the unchanged options-map request. This protects the main reason for this change as well as the returned data.
Knowledge Base Used: Content assets and templates
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Addressed in 3c2dc57 — extracted the sort/icon mapping and entity split into custom-field-mappers.ts and added tests/unit/custom-field-mappers.test.ts, which asserts a mixed, unordered response yields two correctly ordered per-entity lists (client vs company). The single-request and unchanged options-map behavior is covered by the manual test steps in the PR description.
Extract the pure sort/icon mapping and entity split out of useCustomFields into custom-field-mappers, and add unit tests asserting a mixed, unordered response yields two correctly ordered per-entity lists. Guards the consolidated single-request path against regressions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@greptileai review |
Changes
/clientpageload fired two parallelGET /api/custom-fields/[entityType]requests (one forclient, one forcompany), which Sentry's N+1 API Call detector groups by parameterized URL and flags (CLIENT-HOME-V3-1X, OUT-4208).useCustomFieldsnow issues a singleGET /api/custom-fields(the Assembly SDK's no-arglistCustomFields()already returns all entity types) and splits the result intoclientCustomFields/companyCustomFieldsclient-side in auseMemo. The hook's public contract is unchanged.listCustomFieldsroute to the collection path/api/custom-fieldsand removed the now-unused dynamic[entityType]route.options-mapquery untouched to keep the change tightly scoped to the flagged N+1.Testing Criteria
/client?token=<assembly-token>; in DevTools → Network, confirm exactly oneGET /api/custom-fields(200) whosedata[]contains bothentityType: "client"andentityType: "company"— and no/api/custom-fields/clientor/api/custom-fields/companyrequests.order.options-map).GET /api/custom-fields/clientnow returns 404 (dynamic route removed).Notes
Fixes CLIENT-HOME-V3-1Xin the commit auto-closes the Sentry issue on merge.pnpm typecheckandpnpm lintboth pass.Impact & Surface Area of Change
useCustomFields(Segment,useDynamicFields,SegmentFormPanel,SegmentCreationCard,handle-bar-template) are unchanged — same return shape.[entityType]route is removed; verify nothing external hits/api/custom-fields/:entityTypedirectly (only this app's hook did).🤖 Generated with Claude Code