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:
Benny Joo authored and GitHub committed 2025-06-18 09:53:12 +03:00
1 parent 7900be3a30
commit e27de47d9f
4 files changed
+22 -13

No files matched your search

+4 -6
View File
@@ -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;
+14 -3
View File
@@ -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,