Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Dec 24, 2024

What does this PR do?

  • Using possibly faster findUnique for form query instead of findFirst
  • Abstracted out handleResponse from response.handler.ts to be reused in /router - It allows already available form to be passed directly to handleResponse and avoids one sequential query to DB.
  • Passing orgId directly to findTeamMembersMatchingAttributeLogic which helps in restricting the number of records being queried in attributes related tables.
  • Completely different querying approach for getAttributesAssignmentData avoiding some queries in Prisma and using some in memory calculations.

Improvement seen locally:

  • With 2000 members in Acme and half of them being part of the Insights team, querying time went from 442ms(minimum) to 271ms(minimum). The improvements should be more visible with production data which has much much higher number of records.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Test Preview of Routing Form
  • /router endpoint should also work
  • A regular routing form submission should also work

Followup

  • A teamMembershipId column in attributeToUser could possibly save some querying time, if in-memory computation for orgMembershipId to userId doesn't work

Copy link
Contributor

github-actions bot commented Dec 24, 2024

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:

No release type found in pull request title "Add stats and allow showing embed without loader". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Dec 24, 2024 2:34pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Dec 24, 2024 2:34pm

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Dec 24, 2024
@hariombalhara hariombalhara changed the title Add stats and allow showing embed without loader perf: /router endpoint perf improvement Dec 24, 2024
@@ -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));
Copy link
Member Author

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.

Comment on lines -134 to -138
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);
Copy link
Member Author

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

@github-actions github-actions bot added the ❗️ migrations contains migration files label Dec 24, 2024
include: {
team: {
select: {
parentId: true,
Copy link
Member Author

@hariombalhara hariombalhara Dec 24, 2024

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


const form = await prisma.app_RoutingForms_Form.findFirst({
async function findFormById(formId: string, prisma: AppPrisma) {
return await prisma.app_RoutingForms_Form.findUnique({
Copy link
Member Author

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

Copy link
Contributor

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO ❗️ migrations contains migration files ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants