Scheduling infrastructure for absolutely everyone.
perf: leverage DB index for user profile fetching (booking page & payment page) (#21814)
Benny Jooe27de47d9fc3
diff --git a/apps/web/modules/bookings/views/bookings-single-view.getServerSideProps.tsx b/apps/web/modules/bookings/views/bookings-single-view.getServerSideProps.tsxindex 9fee8363228..50fd5eb59b5 100644--- a/apps/web/modules/bookings/views/bookings-single-view.getServerSideProps.tsx+++ b/apps/web/modules/bookings/views/bookings-single-view.getServerSideProps.tsx@@ -234,7 +234,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {eventTypeId: eventType.id,team: eventType.team,owner: eventType.users[0] ?? null,- orgSlug: currentOrgDomain,+ organizationId: session?.user?.profile?.organizationId ?? session?.user?.org?.id ?? null,}),profile,eventType,diff --git a/packages/features/ee/payments/pages/payment.tsx b/packages/features/ee/payments/pages/payment.tsxindex 4eb62a28656..23f55557d44 100644--- a/packages/features/ee/payments/pages/payment.tsx+++ b/packages/features/ee/payments/pages/payment.tsx@@ -1,7 +1,7 @@import type { GetServerSidePropsContext } from "next";import { z } from "zod";-import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";import { getClientSecretFromPayment } from "@calcom/features/ee/payments/pages/getClientSecretFromPayment";import { shouldHideBrandingForEvent } from "@calcom/lib/hideBranding";import prisma from "@calcom/prisma";@@ -18,7 +18,7 @@ const querySchema = z.object({export const getServerSideProps = async (context: GetServerSidePropsContext) => {const { uid } = querySchema.parse(context.query);- const { currentOrgDomain } = orgDomainConfig(context.req);+ const session = await getServerSession({ req: context.req });const rawPayment = await prisma.payment.findUnique({where: {@@ -59,7 +59,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>eventTypeId: eventType.id,team: eventType.team,owner: eventType.users[0] ?? null,- orgSlug: currentOrgDomain,+ organizationId: session?.user?.profile?.organizationId ?? session?.user?.org?.id ?? null,}),};diff --git a/packages/lib/hideBranding.ts b/packages/lib/hideBranding.tsindex 17cf1409d55..745d087ee5c 100644--- a/packages/lib/hideBranding.ts+++ b/packages/lib/hideBranding.ts@@ -24,8 +24,6 @@ type UserWithProfile = UserWithoutProfile & {profile: Profile | null;};-type OrgSlug = string | null;-/*** Determines if branding should be hidden by checking entity and organization settings*/@@ -79,12 +77,12 @@ export async function shouldHideBrandingForEvent({eventTypeId,team,owner,- orgSlug,+ organizationId,}: {eventTypeId: number;team: Team | null;owner: UserWithoutProfile | null;- orgSlug: OrgSlug;+ organizationId: number | null;}) {let ownerProfile = null;if (team) {@@ -94,10 +92,10 @@ export async function shouldHideBrandingForEvent({});} else if (owner) {// Needed only for User events, not for Team events- ownerProfile = orgSlug+ ownerProfile = organizationId? await ProfileRepository.findByUserIdAndOrgSlug({userId: owner.id,- orgSlug,+ organizationId,}): null;diff --git a/packages/lib/server/repository/profile.ts b/packages/lib/server/repository/profile.tsindex 642cb0eb336..7046e8dcc6c 100644--- a/packages/lib/server/repository/profile.ts+++ b/packages/lib/server/repository/profile.ts@@ -665,9 +665,20 @@ export class ProfileRepository {return normalizeProfile(profile);}- static async findByUserIdAndOrgSlug({ userId, orgSlug }: { userId: number; orgSlug: string }) {- const profile = await prisma.profile.findFirst({- where: { userId, organization: { slug: orgSlug } },+ static async findByUserIdAndOrgSlug({+ userId,+ organizationId,+ }: {+ userId: number;+ organizationId: number;+ }) {+ const profile = await prisma.profile.findUnique({+ where: {+ userId_organizationId: {+ userId,+ organizationId,+ },+ },include: {organization: {select: organizationSelect,