perf: Allow bypassing 3rd party calendar busy times (#17492)

* perf: Allow bypassing 3rd party calendar busy times

* Fix typing issues

* Fixed API v1 build

* Another fix for API v1
This commit is contained in:
Keith Williams authored and GitHub committed 2024-11-05 12:31:33 -03:00
1 parent e675ad0c6c
commit ed6d88e30f
8 files changed
+21 -3

No files matched your search

@@ -199,6 +199,7 @@ async function handler(req: NextApiRequest) {
eventTypeId,
userId,
returnDateOverrides: true,
bypassBusyCalendarTimes: false,
});
const team = await prisma.team.findUnique({
where: { id: teamId },
@@ -235,6 +236,7 @@ async function handler(req: NextApiRequest) {
dateTo,
eventTypeId,
returnDateOverrides: true,
bypassBusyCalendarTimes: false,
}),
};
});
+3 -1
View File
@@ -43,6 +43,7 @@ export async function getBusyTimes(params: {
};
})[]
| null;
bypassBusyCalendarTimes: boolean;
}) {
const {
credentials,
@@ -58,6 +59,7 @@ export async function getBusyTimes(params: {
seatedEvent,
rescheduleUid,
duration,
bypassBusyCalendarTimes = false,
} = params;
logger.silly(
@@ -234,7 +236,7 @@ export async function getBusyTimes(params: {
);
performance.mark("prismaBookingGetEnd");
performance.measure(`prisma booking get took $1'`, "prismaBookingGetStart", "prismaBookingGetEnd");
if (credentials?.length > 0) {
if (credentials?.length > 0 && !bypassBusyCalendarTimes) {
const startConnectedCalendarsGet = performance.now();
const calendarBusyTimes = await getBusyCalendarTimes(
username,
+4
View File
@@ -44,6 +44,7 @@ const availabilitySchema = z
duration: z.number().optional(),
withSource: z.boolean().optional(),
returnDateOverrides: z.boolean(),
bypassBusyCalendarTimes: z.boolean().optional(),
})
.refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in.");
@@ -243,6 +244,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
beforeEventBuffer?: number;
duration?: number;
returnDateOverrides: boolean;
bypassBusyCalendarTimes: boolean;
},
initialData?: {
user?: GetUser;
@@ -276,6 +278,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
beforeEventBuffer,
duration,
returnDateOverrides,
bypassBusyCalendarTimes = false,
} = availabilitySchema.parse(query);
if (!dateFrom.isValid() || !dateTo.isValid()) {
@@ -389,6 +392,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
rescheduleUid: initialData?.rescheduleUid || null,
duration,
currentBookings: initialData?.currentBookings,
bypassBusyCalendarTimes,
});
const detailedBusyTimes: EventBusyDetails[] = [
@@ -89,6 +89,7 @@ export async function ensureAvailableUsers(
dateTo: endDateTimeUtc.format(),
beforeEventBuffer: eventType.beforeEventBuffer,
afterEventBuffer: eventType.afterEventBuffer,
bypassBusyCalendarTimes: false,
},
initialData: {
eventType,
@@ -11,5 +11,8 @@ type UserOptions = {
};
export const userHandler = async ({ input }: UserOptions) => {
return getUserAvailability({ returnDateOverrides: true, ...input }, undefined);
return getUserAvailability(
{ returnDateOverrides: true, bypassBusyCalendarTimes: false, ...input },
undefined
);
};
@@ -28,6 +28,7 @@ export const getScheduleSchema = z
routedTeamMemberIds: z.array(z.number()).nullish(),
skipContactOwner: z.boolean().nullish(),
_enableTroubleshooter: z.boolean().optional(),
_bypassCalendarBusyTimes: z.boolean().optional(),
})
.transform((val) => {
// Need this so we can pass a single username in the query string form public API
@@ -406,7 +406,10 @@ export const getAvailableSlots = async (
};
async function _getAvailableSlots({ input, ctx }: GetScheduleOptions): Promise<IGetAvailableSlots> {
const { _enableTroubleshooter: enableTroubleshooter = false } = input;
const {
_enableTroubleshooter: enableTroubleshooter = false,
_bypassCalendarBusyTimes: bypassBusyCalendarTimes = false,
} = input;
const orgDetails = input?.orgSlug
? {
currentOrgDomain: input.orgSlug,
@@ -598,6 +601,7 @@ async function _getAvailableSlots({ input, ctx }: GetScheduleOptions): Promise<I
beforeEventBuffer: eventType.beforeEventBuffer,
duration: input.duration || 0,
returnDateOverrides: false,
bypassBusyCalendarTimes,
},
initialData: {
eventType,
@@ -46,6 +46,7 @@ export const getMemberAvailabilityHandler = async ({ ctx, input }: GetMemberAvai
dateFrom: input.dateFrom,
dateTo: input.dateTo,
returnDateOverrides: true,
bypassBusyCalendarTimes: false,
},
{ user: member.user, busyTimesFromLimitsBookings: [] }
);