refactor: replace shouldServeCache with mode parameter for calendar cache control (#26539)
* refactor: replace shouldServeCache with mode parameter for calendar cache control Replace the boolean shouldServeCache parameter with a new CalendarFetchMode type that can have values 'slots', 'overlay', and 'booking'. This provides better control over when to serve cache vs relay on calendar providers. - 'slots' mode: Check feature flags and use cache when available (for getting actual calendar availability) - 'overlay' mode: Don't use cache (for overlay calendar availability) - 'booking' mode: Don't use cache (for booking confirmation) - undefined: Same as 'slots' for backwards compatibility The cache decision logic is now centralized in getCalendar.ts based on the mode parameter. Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update CalendarService.test.ts to use mode parameter Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: use shared GetAvailabilityParams type across all calendar services - Import GetAvailabilityParams and GetAvailabilityWithTimeZonesParams from @calcom/types/Calendar - Replace inline type definitions with shared types in all calendar service implementations - Update BaseCalendarService, CalendarCacheWrapper, and CalendarTelemetryWrapper - Ensures consistent typing and follows DRY principles Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add missing IntegrationCalendar import and update mock getAvailability signature - Add IntegrationCalendar back to sendgrid CalendarService imports - Update bookingScenario mock getAvailability to use typed params object - Add listCalendars method to mock Calendar object Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update test files to use typed params object for getAvailability methods - Update CalendarCacheWrapper.test.ts to call getAvailability/getAvailabilityWithTimeZones with params object - Update getCalendarsEvents.test.ts toHaveBeenCalledWith assertions to expect params object - All 32 tests now pass Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: consolidate to single GetAvailabilityParams type for both getAvailability methods - Remove GetAvailabilityWithTimeZonesParams, use GetAvailabilityParams for both methods - Add mode parameter to getAvailabilityWithTimeZones calls - Update wrapper classes to pass mode through to underlying calendar - Update test files to include mode in getAvailabilityWithTimeZones calls and assertions Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: use EventBusyDate with optional timeZone for getAvailabilityWithTimeZones - Add optional timeZone field to EventBusyDate type - Update getAvailabilityWithTimeZones return type to use EventBusyDate[] - Update Google Calendar service and wrapper classes to use the new type Co-Authored-By: Volnei Munhoz <[email protected]> * fix: type errors and remove unused calendar watching methods - Fix type errors in CalendarCacheWrapper.ts (convert null to undefined for timeZone) - Fix type errors in getCalendarsEvents.ts (ensure timeZone is always present) - Remove unused watchCalendar/unwatchCalendar from Calendar interface - Remove unused startWatchingCalendarsInGoogle/stopWatchingCalendarsInGoogle from GoogleCalendarService - Remove unused imports (uuid, uniqueBy, GOOGLE_WEBHOOK_URL, ONE_MONTH_IN_MS) Co-Authored-By: Volnei Munhoz <[email protected]> * fix: remove watchCalendar/unwatchCalendar from CalendarTelemetryWrapper Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: remove verbose JSDoc param comments from wrapper classes Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: make mode parameter required in getCalendar Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add required mode parameter to all getCalendar callers Co-Authored-By: Volnei Munhoz <[email protected]> * fix: provide default mode value in getBusyCalendarTimes Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to remaining getCalendar callers Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to vital and wipemycalother reschedule Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to credential-sync API endpoint Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: add 'none' mode to CalendarFetchMode and use as default Co-Authored-By: Volnei Munhoz <[email protected]> * test: add mode parameter to getCalendarsEvents test calls Co-Authored-By: Volnei Munhoz <[email protected]> * Update packages/app-store/delegationCredential.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
37 files changed
+356
-369
No files matched your search
@@ -38,7 +38,7 @@ import type {
|
||||
} from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
||||
import type { CalendarFetchMode, EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
||||
import type { TimeRange } from "@calcom/types/schedule";
|
||||
|
||||
import { findUsersForAvailabilityCheck } from "./findUsersForAvailabilityCheck";
|
||||
@@ -58,7 +58,7 @@ const availabilitySchema = z
|
||||
returnDateOverrides: z.boolean(),
|
||||
bypassBusyCalendarTimes: z.boolean().optional(),
|
||||
silentlyHandleCalendarFailures: z.boolean().optional(),
|
||||
shouldServeCache: z.boolean().optional(),
|
||||
mode: z.enum(["slots", "overlay", "booking"]).optional(),
|
||||
})
|
||||
.refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in.");
|
||||
|
||||
@@ -115,7 +115,7 @@ type GetUserAvailabilityQuery = {
|
||||
returnDateOverrides: boolean;
|
||||
bypassBusyCalendarTimes: boolean;
|
||||
silentlyHandleCalendarFailures?: boolean;
|
||||
shouldServeCache?: boolean;
|
||||
mode?: CalendarFetchMode;
|
||||
};
|
||||
|
||||
export type CurrentSeats = Awaited<
|
||||
@@ -205,7 +205,7 @@ export class UserAvailabilityService {
|
||||
|
||||
for (const credential of delegatedCredentials) {
|
||||
try {
|
||||
const calendar = await getCalendar(credential);
|
||||
const calendar = await getCalendar(credential, "slots");
|
||||
if (calendar && "getMainTimeZone" in calendar && typeof calendar.getMainTimeZone === "function") {
|
||||
const timezone = await calendar.getMainTimeZone();
|
||||
if (timezone && timezone !== "UTC") {
|
||||
@@ -304,7 +304,7 @@ export class UserAvailabilityService {
|
||||
returnDateOverrides,
|
||||
bypassBusyCalendarTimes = false,
|
||||
silentlyHandleCalendarFailures = false,
|
||||
shouldServeCache,
|
||||
mode,
|
||||
} = availabilitySchema.parse(query);
|
||||
|
||||
log.debug(
|
||||
@@ -467,7 +467,7 @@ export class UserAvailabilityService {
|
||||
currentBookings: initialData?.currentBookings,
|
||||
bypassBusyCalendarTimes,
|
||||
silentlyHandleCalendarFailures,
|
||||
shouldServeCache,
|
||||
mode,
|
||||
});
|
||||
} catch (error) {
|
||||
log.error(`Error fetching busy times for user ${username}:`, error);
|
||||
|
||||
Reference in new issue
Block a user