Ensure that availability is fetched in parallel (#14809)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-05-03 13:56:10 +01:00
1 parent 97b2816897
commit 88f4dd2446
3 files changed
+93 -51

No files matched your search

@@ -24,7 +24,7 @@ import { getAppFromSlug } from "@calcom/app-store/utils";
import EventManager from "@calcom/core/EventManager";
import { getEventName } from "@calcom/core/event";
import { getBusyTimesForLimitChecks } from "@calcom/core/getBusyTimes";
import { getUserAvailability } from "@calcom/core/getUserAvailability";
import { getUsersAvailability } from "@calcom/core/getUserAvailability";
import dayjs from "@calcom/dayjs";
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
import {
@@ -362,24 +362,25 @@ export async function ensureAvailableUsers(
});
}
for (const user of eventType.users) {
const { oooExcludedDateRanges: dateRanges, busy: bufferedBusyTimes } = await getUserAvailability(
{
(
await getUsersAvailability({
users: eventType.users,
query: {
...input,
userId: user.id,
eventTypeId: eventType.id,
duration: originalBookingDuration,
returnDateOverrides: false,
dateFrom: startDateTimeUtc.format(),
dateTo: endDateTimeUtc.format(),
},
{
user,
initialData: {
eventType,
rescheduleUid: input.originalRescheduledBooking?.uid ?? null,
busyTimesFromLimitsBookings: busyTimesFromLimitsBookingsAllUsers,
}
);
},
})
).forEach(({ oooExcludedDateRanges: dateRanges, busy: bufferedBusyTimes }, index) => {
const user = eventType.users[index];
log.debug(
"calendarBusyTimes==>>>",
@@ -395,7 +396,7 @@ export async function ensureAvailableUsers(
input,
})
);
continue;
return;
}
let foundConflict = false;
@@ -422,7 +423,7 @@ export async function ensureAvailableUsers(
input,
})
);
continue;
return;
}
try {
@@ -434,7 +435,8 @@ export async function ensureAvailableUsers(
if (!foundConflict) {
availableUsers.push(user);
}
}
});
if (!availableUsers.length) {
loggerWithEventDetails.error(
`No available users found.`,