-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: /router endpoint perf improvement #18366
base: main
Are you sure you want to change the base?
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
|
@@ -178,6 +186,9 @@ export const getServerSideProps = async function getServerSideProps( | |||
serializableForm.fields | |||
); | |||
|
|||
// TODO: To be done using sentry tracing | |||
console.log("Server-Timing", getServerTimingHeader(timeTaken)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite not needed because /router is actually a route now
slug: z.string(), | ||
pages: z.array(z.string()), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing already queried form now.
: null; | ||
|
||
const teamMembersMatchingAttributeLogicWithResult = | ||
formTeamId && formOrgId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Team Members matching logic is applicable only for organization
import * as Router from "./router/[...appPages]"; | ||
import { getServerSideProps as getServerSidePropsRouter } from "./router/getServerSideProps"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved outside of app-pages
@@ -6,7 +6,7 @@ import type { AppGetServerSidePropsContext, AppPrisma } from "@calcom/types/AppG | |||
import { enrichFormWithMigrationData } from "../../enrichFormWithMigrationData"; | |||
import { getSerializableForm } from "../../lib/getSerializableForm"; | |||
|
|||
export async function isAuthorizedToViewTheForm({ | |||
export function isAuthorizedToViewTheForm({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was async accidentally
What does this PR do?
findUnique
for form query instead offindFirst
handleResponse
from response.handler.ts to be reused in /router - It allows already available form to be passed directly tohandleResponse
and avoids one sequential query to DB.orgId
directly tofindTeamMembersMatchingAttributeLogic
which helps in restricting the number of records being queried in attributes related tables.getAttributesAssignmentData
avoidingsome
queries in Prisma and using some in memory calculations.Improvement seen locally:
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Followup
teamMembershipId
column inattributeToUser
could possibly save some querying time, if in-memory computation for orgMembershipId to userId doesn't work