Skip to content

Scheduling infrastructure for absolutely everyone.

perf: Move query to get just the user email to the main get query (#11230)

Alex van Andel4ef52aa2c678
diff --git a/packages/core/getBusyTimes.ts b/packages/core/getBusyTimes.ts
index 297c64e0d1a..b997e2bf8bf 100644
--- a/packages/core/getBusyTimes.ts
+++ b/packages/core/getBusyTimes.ts
@@ -13,6 +13,7 @@ import type { EventBusyDetails } from "@calcom/types/Calendar";
export async function getBusyTimes(params: {
credentials: Credential[];
userId: number;
+ userEmail: string;
username: string;
eventTypeId?: number;
startTime: string;
@@ -27,6 +28,7 @@ export async function getBusyTimes(params: {
const {
credentials,
userId,
+ userEmail,
username,
eventTypeId,
startTime,
@@ -45,15 +47,6 @@ export async function getBusyTimes(params: {
status: BookingStatus.ACCEPTED,
})}`
);
- // get user email for attendee checking.
- const user = await prisma.user.findUniqueOrThrow({
- where: {
- id: userId,
- },
- select: {
- email: true,
- },
- });
/**
* A user is considered busy within a given time period if there
@@ -97,7 +90,7 @@ export async function getBusyTimes(params: {
...sharedQuery,
attendees: {
some: {
- email: user.email,
+ email: userEmail,
},
},
},
diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts
index 3617679d9c3..97834786540 100644
--- a/packages/core/getUserAvailability.ts
+++ b/packages/core/getUserAvailability.ts
@@ -180,6 +180,7 @@ export const getUserAvailability = async function getUsersWorkingHoursLifeTheUni
endTime: getBusyTimesEnd,
eventTypeId,
userId: user.id,
+ userEmail: user.email,
username: `${user.username}`,
beforeEventBuffer,
afterEventBuffer,
diff --git a/packages/prisma/selects/user.ts b/packages/prisma/selects/user.ts
index 3da14c31a06..9c62e70275c 100644
--- a/packages/prisma/selects/user.ts
+++ b/packages/prisma/selects/user.ts
@@ -3,6 +3,7 @@ import { Prisma } from "@prisma/client";
export const availabilityUserSelect = Prisma.validator<Prisma.UserSelect>()({
id: true,
timeZone: true,
+ email: true,
bufferTime: true,
startTime: true,
username: true,
@@ -22,7 +23,6 @@ export const availabilityUserSelect = Prisma.validator<Prisma.UserSelect>()({
});
export const baseUserSelect = Prisma.validator<Prisma.UserSelect>()({
- email: true,
name: true,
destinationCalendar: true,
locale: true,
@@ -35,7 +35,6 @@ export const baseUserSelect = Prisma.validator<Prisma.UserSelect>()({
export const userSelect = Prisma.validator<Prisma.UserArgs>()({
select: {
- email: true,
name: true,
allowDynamicBooking: true,
destinationCalendar: true,