From 0aad5520ccc0d95de936f3233e8daf4311f1170b Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:28:53 +0200 Subject: [PATCH] chore: ensure default selected calendars in calendars processor job (#26944) * chore: ensure default selected calendars handleEnsureDefaultCalendars * fix: bypass cache when ensureDefaultSelectedCalendars is true When ensureDefaultSelectedCalendars is true, the cache should be bypassed to ensure the defaults logic actually runs. Previously, cached data would be returned before the ensure-defaults logic could execute. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../processors/calendars.processor.ts | 6 +-- .../calendars/services/calendars.service.ts | 41 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/apps/api/v2/src/ee/calendars/processors/calendars.processor.ts b/apps/api/v2/src/ee/calendars/processors/calendars.processor.ts index 9422e6b3d8..5f550ce6e2 100644 --- a/apps/api/v2/src/ee/calendars/processors/calendars.processor.ts +++ b/apps/api/v2/src/ee/calendars/processors/calendars.processor.ts @@ -1,7 +1,7 @@ -import { CalendarsService } from "@/ee/calendars/services/calendars.service"; import { Process, Processor } from "@nestjs/bull"; import { Logger } from "@nestjs/common"; import { Job } from "bull"; +import { CalendarsService } from "@/ee/calendars/services/calendars.service"; export const DEFAULT_CALENDARS_JOB = "default_calendars_job"; export const CALENDARS_QUEUE = "calendars"; @@ -20,8 +20,8 @@ export class CalendarsProcessor { const { userId } = job.data; try { // getCalendars calls getConnectedDestinationCalendarsAndEnsureDefaultsInDb from platform libraries - // which gets the calendars from third party providers and ensure default calendars are set in DB - await this.calendarsService.getCalendars(userId); + // which gets the calendars from third party providers and ensure default destination and selected calendars are set in DB + await this.calendarsService.getCalendars(userId, true); } catch (err) { this.logger.error(`Failed to load default calendars of user with id: ${userId}`, { userId, diff --git a/apps/api/v2/src/ee/calendars/services/calendars.service.ts b/apps/api/v2/src/ee/calendars/services/calendars.service.ts index 727dd951c4..a3bccec5b6 100644 --- a/apps/api/v2/src/ee/calendars/services/calendars.service.ts +++ b/apps/api/v2/src/ee/calendars/services/calendars.service.ts @@ -1,3 +1,20 @@ +import { APPS_TYPE_ID_MAPPING } from "@calcom/platform-constants"; +import { + type EventBusyDate, + getBusyCalendarTimes, + getConnectedDestinationCalendarsAndEnsureDefaultsInDb, +} from "@calcom/platform-libraries"; +import type { Calendar } from "@calcom/platform-types"; +import type { PrismaClient } from "@calcom/prisma"; +import type { Prisma, User } from "@calcom/prisma/client"; +import { + Injectable, + InternalServerErrorException, + NotFoundException, + UnauthorizedException, +} from "@nestjs/common"; +import { DateTime } from "luxon"; +import { z } from "zod"; import { CalendarsRepository } from "@/ee/calendars/calendars.repository"; import { CalendarsCacheService } from "@/ee/calendars/services/calendars-cache.service"; import { AppsRepository } from "@/modules/apps/apps.repository"; @@ -8,24 +25,6 @@ import { import { PrismaWriteService } from "@/modules/prisma/prisma-write.service"; import { SelectedCalendarsRepository } from "@/modules/selected-calendars/selected-calendars.repository"; import { UsersRepository } from "@/modules/users/users.repository"; -import { - Injectable, - InternalServerErrorException, - NotFoundException, - UnauthorizedException, -} from "@nestjs/common"; -import { DateTime } from "luxon"; -import { z } from "zod"; - -import { APPS_TYPE_ID_MAPPING } from "@calcom/platform-constants"; -import { - getBusyCalendarTimes, - getConnectedDestinationCalendarsAndEnsureDefaultsInDb, - type EventBusyDate, -} from "@calcom/platform-libraries"; -import type { Calendar } from "@calcom/platform-types"; -import type { PrismaClient } from "@calcom/prisma"; -import type { Prisma, User } from "@calcom/prisma/client"; @Injectable() export class CalendarsService { @@ -52,10 +51,10 @@ export class CalendarsService { .filter((credential) => !!credential); } - async getCalendars(userId: number) { + async getCalendars(userId: number, ensureDefaultSelectedCalendars = false) { const cachedResult = await this.calendarsCacheService.getConnectedAndDestinationCalendarsCache(userId); - if (cachedResult) { + if (cachedResult && !ensureDefaultSelectedCalendars) { return cachedResult; } @@ -71,7 +70,7 @@ export class CalendarsService { (calendar) => !calendar.eventTypeId ), }, - onboarding: false, + onboarding: ensureDefaultSelectedCalendars, eventTypeId: null, prisma: this.dbWrite.prisma as unknown as PrismaClient, });