feat: CalendarCache - filter generic calendars from subscription batch#7
Conversation
Add filtering to SelectedCalendarRepository.findNextSubscriptionBatch to exclude generic calendars (holidays, contacts, shared, imported, resources) based on their externalId suffixes. Changes: - Add GENERIC_CALENDAR_SUFFIXES constant mapping providers to their generic calendar suffixes in AdaptersFactory - Add getGenericCalendarSuffixes method to AdapterFactory interface - Update findNextSubscriptionBatch to accept and use genericCalendarSuffixes parameter to filter out calendars with matching externalId suffixes - Update CalendarSubscriptionService.checkForNewSubscriptions to pass generic calendar suffixes from the adapter factory - Update tests to cover the new filtering logic Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
Code Review by Qodo
1. Repository filename/class mismatch
|
| import type { Prisma } from "@calcom/prisma/client"; | ||
|
|
||
| export class SelectedCalendarRepository implements ISelectedCalendarRepository { | ||
| export class PrismaSelectedCalendarRepository implements ISelectedCalendarRepository { |
There was a problem hiding this comment.
1. Repository filename/class mismatch 📘 Rule violation ✓ Correctness
• The repository file is named SelectedCalendarRepository.ts but now exports PrismaSelectedCalendarRepository, violating the required Prisma<Entity>Repository filename/class convention. • This reduces consistency/discoverability and can confuse imports and code search for the canonical repository implementation.
Agent prompt
## Issue description
`PrismaSelectedCalendarRepository` is exported from `SelectedCalendarRepository.ts`, but repositories must follow the `Prisma<Entity>Repository.ts` naming convention with filename matching the exported class name.
## Issue Context
This violates the repository naming convention and can reduce discoverability and consistency across the codebase.
## Fix Focus Areas
- packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts[1-6]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| take, | ||
| teamIds, | ||
| integrations, | ||
| genericCalendarSuffixes, | ||
| }: { | ||
| take: number; | ||
| teamIds: number[]; | ||
| integrations: string[]; | ||
| genericCalendarSuffixes?: string[]; | ||
| }) { | ||
| return this.prismaClient.selectedCalendar.findMany({ | ||
| where: { |
There was a problem hiding this comment.
2. Integrations optional mismatch 🐞 Bug ⛯ Reliability
• ISelectedCalendarRepository.findNextSubscriptionBatch declares integrations as optional, but the Prisma implementation requires it and uses it unguarded. • If any caller omits integrations (allowed by the interface), Prisma will receive in: undefined and likely throw at runtime. • This is also a contract mismatch between interface and implementation that invites future bugs.
Agent prompt
### Issue description
`integrations` is optional in `ISelectedCalendarRepository.findNextSubscriptionBatch`, but the Prisma implementation requires it and uses it directly in `integration: { in: integrations }`. If a caller omits `integrations` (which the interface allows), this can cause a Prisma validation/runtime error.
### Issue Context
This PR adds another optional filter (`genericCalendarSuffixes`) and handles it defensively, making the lack of defensive handling for `integrations` more inconsistent and risky.
### Fix Focus Areas
- packages/features/selectedCalendar/repositories/SelectedCalendarRepository.interface.ts[26-36]
- packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts[18-33]
### Suggested fix options
- Option A: Make `integrations` required in the interface (and update any callers/tests accordingly).
- Option B (more flexible): Keep it optional and update implementation:
- Use `integration: integrations?.length ? { in: integrations } : undefined` (or conditionally spread the filter) so Prisma doesn't receive `in: undefined`.
- Decide expected behavior when `integrations` is omitted (e.g., return all integrations vs. return none).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#7