perf: /router endpoint perf improvement#18366
Conversation
acba639 to
9379810
Compare
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
| ); | ||
|
|
||
| // TODO: To be done using sentry tracing | ||
| console.log("Server-Timing", getServerTimingHeader(timeTaken)); |
There was a problem hiding this comment.
timeTaken is already being computed, so I will just use the same approach for now for quick release. I will later move it to Sentry.
| const { createContext } = await import("@calcom/trpc/server/createContext"); | ||
| const ctx = await createContext(context); | ||
|
|
||
| const { default: trpcRouter } = await import("@calcom/app-store/routing-forms/trpc/_router"); | ||
| const caller = trpcRouter.createCaller(ctx); |
There was a problem hiding this comment.
Avoid using another trpcHandler and instead use the utility directly.
Also, needed to do this so that I can easily pass on already queried form to handleResponse and avoid repeat querying of same data
9379810 to
86bb2ba
Compare
| include: { | ||
| team: { | ||
| select: { | ||
| parentId: true, |
There was a problem hiding this comment.
New requirement, it was already queried in /router endpoint for some other requirement
86bb2ba to
1d9d8cb
Compare
|
|
||
| const form = await prisma.app_RoutingForms_Form.findFirst({ | ||
| async function findFormById(formId: string, prisma: AppPrisma) { | ||
| return await prisma.app_RoutingForms_Form.findUnique({ |
There was a problem hiding this comment.
Using findUnique instead of findFirst
1d9d8cb to
6f56f8e
Compare
6f56f8e to
3dff0ca
Compare
E2E results are ready! |
| source: "/router/:path*", | ||
| destination: "/apps/routing-forms/router/:path*", | ||
| }, |
There was a problem hiding this comment.
Rewrite not needed because /router is actually a route now
| form: z.string(), | ||
| slug: z.string(), | ||
| pages: z.array(z.string()), | ||
| }) |
There was a problem hiding this comment.
Slug pages was there because it was earlier under app-store. Now it is not needed.
| const { form: formId, embed, ...fieldsResponses } = queryParsed.data; | ||
| const { currentOrgDomain } = orgDomainConfig(context.req); | ||
|
|
||
| let timeTaken: Record<string, number | null> = {}; |
There was a problem hiding this comment.
Commented at other places as well but comment here as well. Time Taken is an existing approach that I am adding more data on. This later needs to move to Sentry performance tracing
| const result = await caller.public.response({ | ||
| formId: form.id, | ||
| const result = await handleResponse({ | ||
| form: serializableForm, |
There was a problem hiding this comment.
Passing already queried form now.
| : null; | ||
|
|
||
| const teamMembersMatchingAttributeLogicWithResult = | ||
| formTeamId && formOrgId |
There was a problem hiding this comment.
Team Members matching logic is applicable only for organization
| "pages/api/trpc/appRoutingForms/[trpc].ts": { | ||
| "memory": 2048 | ||
| }, | ||
| "pages/router/embed.tsx": { |
There was a problem hiding this comment.
Not sure if page route will work but I am assuming it would.
Giving it more vCPUs, because there are a lot of computations that happen through this route's getServerSideProps -> handleResponse -> findTeamMembersMatchingAttributeLogic
There was a problem hiding this comment.
We could add non embed route as well later but for now this is necessary.
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (12/26/24)1 reviewer was added to this PR based on Keith Williams's automation. "Add foundation team as reviewer" took an action on this PR • (12/26/24)1 reviewer was added to this PR based on Keith Williams's automation. |
Udit-takkar
left a comment
There was a problem hiding this comment.
Screen.Recording.2024-12-26.at.1.53.45.PM.mov
Whenever i type a letter the input looses focus and i have to click again to type the next letter.
Not sure if this bug was introduced in this PR
That is weird. I don't think I touched anything in there. |
keithwillcode
left a comment
There was a problem hiding this comment.
Why aren't we using the Sentry perf tracing instead of log messages?
Udit-takkar
left a comment
There was a problem hiding this comment.
LGTM.
This issue #18366 (review) is not related to this PR
|
@keithwillcode Time taken was already computed earlier,I am just logging thode in this PR and added 2 more cases I believe Will tackle move to sentry in a followup |
What does this PR do?
findUniquefor form query instead offindFirsthandleResponsefrom response.handler.ts to be reused in /router - It allows already available form to be passed directly tohandleResponseand avoids one sequential query to DB.orgIddirectly tofindTeamMembersMatchingAttributeLogicwhich helps in restricting the number of records being queried in attributes related tables.getAttributesAssignmentDataavoidingsomequeries in Prisma and using some in memory calculations.Sample
Server-Timing formQuery;dur=4.965374946594238, profileEnrichment;dur=1.2969579696655273, getSerializableForm;dur=14.026041984558105, ttgetAttributesQueryBuilderConfigHavingListofLabels;dur=0.6570830345153809, ttTeamMembersMatchingAttributeLogic;dur=23.702916860580444, ttGetAttributesForLogic;dur=292.05258297920227
Improvement seen locally:
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Followup
teamMembershipIdcolumn inattributeToUsercould possibly save some querying time, if in-memory computation for orgMembershipId to userId doesn't work