perf: Improved buildDateRanges performance + cleanup (#10610)
Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
This commit is contained in:
parent
6b536030fa
commit
e5f15cb1df
|
@ -3,10 +3,7 @@ import { intersect } from "@calcom/lib/date-ranges";
|
|||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
|
||||
export const getAggregatedAvailability = (
|
||||
userAvailability: (Omit<
|
||||
Awaited<ReturnType<Awaited<typeof import("./getUserAvailability")>["getUserAvailability"]>>,
|
||||
"currentSeats"
|
||||
> & { user?: { isFixed?: boolean } })[],
|
||||
userAvailability: { dateRanges: DateRange[]; user?: { isFixed?: boolean } }[],
|
||||
schedulingType: SchedulingType | null
|
||||
): DateRange[] => {
|
||||
const fixedHosts = userAvailability.filter(
|
||||
|
|
|
@ -93,7 +93,7 @@ export function buildDateRanges({
|
|||
...groupedDateOverrides,
|
||||
}).map(
|
||||
// remove 0-length overrides that were kept to cancel out working dates until now.
|
||||
(ranges) => ranges.filter((range) => !range.start.isSame(range.end))
|
||||
(ranges) => ranges.filter((range) => range.start.valueOf() !== range.end.valueOf())
|
||||
);
|
||||
|
||||
return dateRanges.flat();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { countBy } from "lodash";
|
||||
import { v4 as uuid } from "uuid";
|
||||
|
||||
import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours";
|
||||
import { getAggregatedAvailability } from "@calcom/core/getAggregatedAvailability";
|
||||
import type { CurrentSeats } from "@calcom/core/getUserAvailability";
|
||||
import { getUserAvailability } from "@calcom/core/getUserAvailability";
|
||||
|
@ -229,8 +228,6 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
usersWithCredentials.map(async (currentUser) => {
|
||||
const {
|
||||
busy,
|
||||
workingHours,
|
||||
dateOverrides,
|
||||
dateRanges,
|
||||
currentSeats: _currentSeats,
|
||||
timeZone,
|
||||
|
@ -254,8 +251,6 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
if (!currentSeats && _currentSeats) currentSeats = _currentSeats;
|
||||
return {
|
||||
timeZone,
|
||||
workingHours,
|
||||
dateOverrides,
|
||||
dateRanges,
|
||||
busy,
|
||||
user: currentUser,
|
||||
|
@ -263,11 +258,6 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
})
|
||||
);
|
||||
|
||||
// flattens availability of multiple users
|
||||
const dateOverrides = userAvailability.flatMap((availability) =>
|
||||
availability.dateOverrides.map((override) => ({ userId: availability.user.id, ...override }))
|
||||
);
|
||||
const workingHours = getAggregateWorkingHours(userAvailability, eventType.schedulingType);
|
||||
const availabilityCheckProps = {
|
||||
eventLength: input.duration || eventType.length,
|
||||
currentSeats,
|
||||
|
@ -290,8 +280,6 @@ export async function getAvailableSlots(input: TGetScheduleInputSchema) {
|
|||
const timeSlots = getSlots({
|
||||
inviteeDate: startTime,
|
||||
eventLength: input.duration || eventType.length,
|
||||
workingHours,
|
||||
dateOverrides,
|
||||
offsetStart: eventType.offsetStart,
|
||||
dateRanges: getAggregatedAvailability(userAvailability, eventType.schedulingType),
|
||||
minimumBookingNotice: eventType.minimumBookingNotice,
|
||||
|
|
Loading…
Reference in New Issue
Block a user