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>
This commit is contained in:
Morgan
2026-01-19 17:28:53 +09:00
committed by GitHub
co-authored by unknown Devin AI
parent adc4272545
commit 0aad5520cc
2 changed files with 23 additions and 24 deletions
@@ -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,
@@ -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,
});