-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: run parallel bookings queries #16398
Changes from all commits
04c93ce
785a137
b632bb3
14a049d
c39f7d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -505,71 +505,88 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro | |||||||||
}; | ||||||||||
|
||||||||||
const allUserIds = usersWithCredentials.map((user) => user.id); | ||||||||||
const bookingsSelect = { | ||||||||||
id: true, | ||||||||||
uid: true, | ||||||||||
userId: true, | ||||||||||
startTime: true, | ||||||||||
endTime: true, | ||||||||||
title: true, | ||||||||||
attendees: true, | ||||||||||
eventType: { | ||||||||||
select: { | ||||||||||
id: true, | ||||||||||
onlyShowFirstAvailableSlot: true, | ||||||||||
afterEventBuffer: true, | ||||||||||
beforeEventBuffer: true, | ||||||||||
seatsPerTimeSlot: true, | ||||||||||
requiresConfirmationWillBlockSlot: true, | ||||||||||
requiresConfirmation: true, | ||||||||||
}, | ||||||||||
}, | ||||||||||
...(!!eventType?.seatsPerTimeSlot && { | ||||||||||
_count: { | ||||||||||
select: { | ||||||||||
seatsReferences: true, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}), | ||||||||||
}; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
const currentBookingsAllUsers = await prisma.booking.findMany({ | ||||||||||
const currentBookingsAllUsersQueryOne = prisma.booking.findMany({ | ||||||||||
where: { | ||||||||||
OR: [ | ||||||||||
// User is primary host (individual events, or primary organizer) | ||||||||||
{ | ||||||||||
...sharedQuery, | ||||||||||
userId: { | ||||||||||
in: allUserIds, | ||||||||||
}, | ||||||||||
}, | ||||||||||
// The current user has a different booking at this time he/she attends | ||||||||||
{ | ||||||||||
...sharedQuery, | ||||||||||
attendees: { | ||||||||||
some: { | ||||||||||
email: { | ||||||||||
in: usersWithCredentials.map((user) => user.email), | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
{ | ||||||||||
startTime: { lte: endTimeDate }, | ||||||||||
endTime: { gte: startTimeDate }, | ||||||||||
eventType: { | ||||||||||
id: eventType.id, | ||||||||||
requiresConfirmation: true, | ||||||||||
requiresConfirmationWillBlockSlot: true, | ||||||||||
}, | ||||||||||
status: { | ||||||||||
in: [BookingStatus.PENDING], | ||||||||||
...sharedQuery, | ||||||||||
userId: { | ||||||||||
in: allUserIds, | ||||||||||
}, | ||||||||||
}, | ||||||||||
select: { | ||||||||||
...bookingsSelect, | ||||||||||
}, | ||||||||||
Comment on lines
+543
to
+545
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for spreading.
Suggested change
|
||||||||||
}); | ||||||||||
|
||||||||||
const currentBookingsAllUsersQueryTwo = prisma.booking.findMany({ | ||||||||||
where: { | ||||||||||
...sharedQuery, | ||||||||||
attendees: { | ||||||||||
some: { | ||||||||||
email: { | ||||||||||
in: usersWithCredentials.map((user) => user.email), | ||||||||||
}, | ||||||||||
}, | ||||||||||
], | ||||||||||
}, | ||||||||||
}, | ||||||||||
select: { | ||||||||||
id: true, | ||||||||||
uid: true, | ||||||||||
userId: true, | ||||||||||
startTime: true, | ||||||||||
endTime: true, | ||||||||||
title: true, | ||||||||||
attendees: true, | ||||||||||
...bookingsSelect, | ||||||||||
}, | ||||||||||
Comment on lines
559
to
+561
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. No need to spread . |
||||||||||
}); | ||||||||||
|
||||||||||
const currentBookingsAllUsersQueryThree = prisma.booking.findMany({ | ||||||||||
where: { | ||||||||||
startTime: { lte: endTimeDate }, | ||||||||||
endTime: { gte: startTimeDate }, | ||||||||||
eventType: { | ||||||||||
select: { | ||||||||||
id: true, | ||||||||||
onlyShowFirstAvailableSlot: true, | ||||||||||
afterEventBuffer: true, | ||||||||||
beforeEventBuffer: true, | ||||||||||
seatsPerTimeSlot: true, | ||||||||||
requiresConfirmationWillBlockSlot: true, | ||||||||||
requiresConfirmation: true, | ||||||||||
}, | ||||||||||
id: eventType.id, | ||||||||||
requiresConfirmation: true, | ||||||||||
requiresConfirmationWillBlockSlot: true, | ||||||||||
}, | ||||||||||
status: { | ||||||||||
in: [BookingStatus.PENDING], | ||||||||||
}, | ||||||||||
...(!!eventType?.seatsPerTimeSlot && { | ||||||||||
_count: { | ||||||||||
select: { | ||||||||||
seatsReferences: true, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}), | ||||||||||
}, | ||||||||||
select: { | ||||||||||
...bookingsSelect, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||||||||||
}, | ||||||||||
}); | ||||||||||
|
||||||||||
const [resultOne, resultTwo, resultThree] = await Promise.all([ | ||||||||||
currentBookingsAllUsersQueryOne, | ||||||||||
currentBookingsAllUsersQueryTwo, | ||||||||||
currentBookingsAllUsersQueryThree, | ||||||||||
]); | ||||||||||
|
||||||||||
const currentBookingsAllUsers = [...resultOne, ...resultTwo, ...resultThree]; | ||||||||||
|
||||||||||
const bookingLimits = parseBookingLimit(eventType?.bookingLimits); | ||||||||||
const durationLimits = parseDurationLimit(eventType?.durationLimits); | ||||||||||
let busyTimesFromLimitsBookingsAllUsers: Awaited<ReturnType<typeof getBusyTimesForLimitChecks>> = []; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.