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

This commit is contained in:
Alex van Andel 2023-09-08 12:39:29 +01:00 committed by GitHub
parent 3132c64205
commit 4ef52aa2c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 12 deletions

View File

@ -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,
},
},
},

View File

@ -180,6 +180,7 @@ export const getUserAvailability = async function getUsersWorkingHoursLifeTheUni
endTime: getBusyTimesEnd,
eventTypeId,
userId: user.id,
userEmail: user.email,
username: `${user.username}`,
beforeEventBuffer,
afterEventBuffer,

View File

@ -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,