perf: leverage DB index for user profile fetching (booking page & payment page) (#21814)
* leverage DB index for findByUserIdAndOrgSlug method * booking view * payment view * fix * fix * address comment
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user