From 53bbbf793d046e0383c292c1c617ca3bcdb5d603 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Thu, 30 Jun 2022 01:33:19 +0100 Subject: [PATCH] Fixes the slow performance due to the Dayjs timezone plugin (#3201) * Fixes the slow performance due to the Dayjs timezone plugin * Bye. * Parses busyTime in UTC --- apps/web/server/routers/viewer/slots.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/web/server/routers/viewer/slots.tsx b/apps/web/server/routers/viewer/slots.tsx index b6c217b3c3..8d6e416c6f 100644 --- a/apps/web/server/routers/viewer/slots.tsx +++ b/apps/web/server/routers/viewer/slots.tsx @@ -4,7 +4,6 @@ import { z } from "zod"; import type { CurrentSeats } from "@calcom/core/getUserAvailability"; import { getUserAvailability } from "@calcom/core/getUserAvailability"; import dayjs, { Dayjs } from "@calcom/dayjs"; -import { yyyymmdd } from "@calcom/lib/date-fns"; import { availabilityUserSelect } from "@calcom/prisma"; import { stringToDayjs } from "@calcom/prisma/zod-utils"; import { TimeRange } from "@calcom/types/schedule"; @@ -59,15 +58,16 @@ const checkForAvailability = ({ return true; } - const slotEndTime = time.add(eventLength, "minutes"); - const slotStartTimeWithBeforeBuffer = time.subtract(beforeBufferTime, "minutes"); - const slotEndTimeWithAfterBuffer = time.add(eventLength + afterBufferTime, "minutes"); + const slotEndTime = time.add(eventLength, "minutes").utc(); + const slotStartTimeWithBeforeBuffer = time.subtract(beforeBufferTime, "minutes").utc(); + const slotEndTimeWithAfterBuffer = time.add(eventLength + afterBufferTime, "minutes").utc(); + + return busy.every((busyTime) => { + const startTime = dayjs.utc(busyTime.start); + const endTime = dayjs.utc(busyTime.end); - return busy.every((busyTime): boolean => { - const startTime = dayjs(busyTime.start); - const endTime = dayjs(busyTime.end); // Check if start times are the same - if (time.isBetween(startTime, endTime, null, "[)")) { + if (time.utc().isBetween(startTime, endTime, null, "[)")) { return false; } // Check if slot end time is between start and end time