From 6c5b12db57f8dccbc9a0f1ed5edb7bc837919ea5 Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Sun, 3 Nov 2024 12:21:35 -0300 Subject: [PATCH] perf: Add more specific spans to getBusyTimes (#17437) * perf: Add more specific spans to getBusyTimes * fix types --- packages/core/getBusyTimes.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/getBusyTimes.ts b/packages/core/getBusyTimes.ts index 7b3db48ad2..c8c62c1ef9 100644 --- a/packages/core/getBusyTimes.ts +++ b/packages/core/getBusyTimes.ts @@ -1,5 +1,6 @@ import type { Booking, EventType } from "@prisma/client"; import { Prisma } from "@prisma/client"; +import * as Sentry from "@sentry/nextjs"; import { getBusyCalendarTimes } from "@calcom/core/CalendarManager"; import dayjs from "@calcom/dayjs"; @@ -110,6 +111,7 @@ export async function getBusyTimes(params: { let bookings = params.currentBookings; if (!bookings) { + const getBookingsForBusyTimesSpan = Sentry.startInactiveSpan({ name: "getBookingsForBusyTimes" }); const bookingsSelect = Prisma.validator()({ id: true, uid: true, @@ -180,6 +182,8 @@ export async function getBusyTimes(params: { ]); bookings = [...resultOne, ...resultTwo, ...(resultThree ?? [])]; + + getBookingsForBusyTimesSpan.end(); } const bookingSeatCountMap: { [x: string]: number } = {}; @@ -249,6 +253,8 @@ export async function getBusyTimes(params: { }) ); + const openSeatsDateRangesSpan = Sentry.startInactiveSpan({ name: "openSeatsDateRanges" }); + const openSeatsDateRanges = Object.keys(bookingSeatCountMap).map((key) => { const [start, end] = key.split("<>"); return { @@ -257,6 +263,8 @@ export async function getBusyTimes(params: { }; }); + openSeatsDateRangesSpan.end(); + if (rescheduleUid) { const originalRescheduleBooking = bookings.find((booking) => booking.uid === rescheduleUid); // calendar busy time from original rescheduled booking should not be blocked @@ -268,6 +276,7 @@ export async function getBusyTimes(params: { } } + const finalizeBusyTimesSpan = Sentry.startInactiveSpan({ name: "finalizeBusyTimes" }); const result = subtract( calendarBusyTimes.map((value) => ({ ...value, @@ -285,6 +294,8 @@ export async function getBusyTimes(params: { })) ); + finalizeBusyTimesSpan.end(); + /* // TODO: Disabled until we can filter Zoom events by date. Also this is adding too much latency. const videoBusyTimes = (await getBusyVideoTimes(credentials)).filter(notEmpty);