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:
authored and GitHub committed 2026-01-08 09:07:41 -03:00
1 parent 64828abad2
commit a62eb2bdac
37 files changed
+356 -369

No files matched your search

@@ -83,12 +83,14 @@ export const calendarOverlayHandler = async ({ ctx, input }: ListOptions) => {
};
});
// get all clanedar services
// get all calendar services
// Use "overlay" mode to bypass cache for overlay calendar availability
const calendarBusyTimesQuery = await getBusyCalendarTimes(
credentials,
dateFrom,
dateTo,
composedSelectedCalendars
composedSelectedCalendars,
"overlay"
);
if (!calendarBusyTimesQuery.success) {
@@ -52,7 +52,7 @@ import { safeStringify } from "@calcom/lib/safeStringify";
import { withReporting } from "@calcom/lib/sentryWrapper";
import type { RoutingFormResponseRepository } from "@calcom/lib/server/repository/formResponse";
import { PeriodType, SchedulingType } from "@calcom/prisma/enums";
import type { EventBusyDate, EventBusyDetails } from "@calcom/types/Calendar";
import type { CalendarFetchMode, EventBusyDate, EventBusyDetails } from "@calcom/types/Calendar";
import type { CredentialForCalendarService } from "@calcom/types/Credential";
import { TRPCError } from "@trpc/server";
import type { Logger } from "tslog";
@@ -786,7 +786,7 @@ export class AvailableSlotsService {
endTime,
bypassBusyCalendarTimes,
silentCalendarFailures,
shouldServeCache,
mode,
}: {
input: TGetScheduleInputSchema;
eventType: Exclude<
@@ -803,7 +803,7 @@ export class AvailableSlotsService {
endTime: Dayjs;
bypassBusyCalendarTimes: boolean;
silentCalendarFailures: boolean;
shouldServeCache?: boolean;
mode?: CalendarFetchMode;
}) {
const usersWithCredentials = this.getUsersWithCredentials({
hosts,
@@ -940,7 +940,7 @@ export class AvailableSlotsService {
returnDateOverrides: false,
bypassBusyCalendarTimes,
silentlyHandleCalendarFailures: silentCalendarFailures,
shouldServeCache,
mode,
},
initialData: {
eventType,
@@ -1032,7 +1032,8 @@ export class AvailableSlotsService {
throw new TRPCError({ code: "NOT_FOUND" });
}
const shouldServeCache = false;
// Use "slots" mode to enable cache when available for getting calendar availability
const mode: CalendarFetchMode = "slots";
if (isEventTypeLoggingEnabled({ eventTypeId: eventType.id })) {
logger.settings.minLevel = 2;
}
@@ -1141,7 +1142,7 @@ export class AvailableSlotsService {
: endTime,
bypassBusyCalendarTimes,
silentCalendarFailures,
shouldServeCache,
mode,
});
let aggregatedAvailability = getAggregatedAvailability(allUsersAvailability, eventType.schedulingType);
@@ -1168,7 +1169,7 @@ export class AvailableSlotsService {
endTime: twoWeeksFromNow,
bypassBusyCalendarTimes,
silentCalendarFailures,
shouldServeCache,
mode,
});
if (
!getAggregatedAvailability(
@@ -1204,7 +1205,7 @@ export class AvailableSlotsService {
endTime,
bypassBusyCalendarTimes,
silentCalendarFailures,
shouldServeCache,
mode,
}));
aggregatedAvailability = getAggregatedAvailability(allUsersAvailability, eventType.schedulingType);
}