Skip to content

Commit

Permalink
perf: getAvailableSlots improvements (#18382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Udit-takkar authored Dec 27, 2024
1 parent 1aee174 commit 558c8be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
6 changes: 2 additions & 4 deletions packages/lib/bookings/filterHostsByLeadThreshold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ describe("filterHostByLeadThreshold", () => {
where: {
OR: [
{
user: {
id: {
in: [2],
},
userId: {
in: [2],
},
OR: [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/lib/server/repository/booking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ const buildWhereClauseForActiveBookings = ({
}): Prisma.BookingWhereInput => ({
OR: [
{
user: {
id: {
in: users.map((user) => user.id),
},
userId: {
in: users.map((user) => user.id),
},
OR: [
{
Expand Down
28 changes: 12 additions & 16 deletions packages/trpc/server/routers/viewer/slots/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,22 +986,18 @@ const calculateHostsAndAvailabilities = async ({
};

const allUserIds = usersWithCredentials.map((user) => user.id);
const currentBookingsAllUsers = await monitorCallbackAsync(
getExistingBookings,
startTimeDate,
endTimeDate,
eventType,
sharedQuery,
usersWithCredentials,
allUserIds
);

const outOfOfficeDaysAllUsers = await monitorCallbackAsync(
getOOODates,
startTimeDate,
endTimeDate,
allUserIds
);
const [currentBookingsAllUsers, outOfOfficeDaysAllUsers] = await Promise.all([
monitorCallbackAsync(
getExistingBookings,
startTimeDate,
endTimeDate,
eventType,
sharedQuery,
usersWithCredentials,
allUserIds
),
monitorCallbackAsync(getOOODates, startTimeDate, endTimeDate, allUserIds),
]);

const bookingLimits = parseBookingLimit(eventType?.bookingLimits);
const durationLimits = parseDurationLimit(eventType?.durationLimits);
Expand Down

0 comments on commit 558c8be

Please sign in to comment.