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>
📝 WalkthroughWalkthroughThe PR introduces a feature to exclude generic calendar entries (such as Google Calendar's default calendar or Office 365's primary calendar) from subscription batching. It adds a configuration mapping generic calendar suffixes by provider, exposes this through the adapter factory, and implements filtering logic in the repository layer to exclude calendars matching those suffixes. Changes
Sequence DiagramsequenceDiagram
participant Service as CalendarSubscriptionService
participant Factory as AdapterFactory
participant Repository as SelectedCalendarRepository
participant DB as Database
Service->>Factory: getGenericCalendarSuffixes()
Factory-->>Service: string[]
Service->>Service: checkForNewSubscriptions()
Service->>Repository: findNextSubscriptionBatch({<br/>take, teamIds, integrations,<br/>genericCalendarSuffixes})
Repository->>Repository: Build where clause with<br/>NOT conditions for suffixes
Repository->>DB: Query SelectedCalendar with<br/>filtering on externalId
DB-->>Repository: SelectedCalendar[]
Repository-->>Service: Filtered results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
1 similar comment
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts`:
- Around line 5-6: Update the test that still imports the old class name:
replace the import of SelectedCalendarRepository in the test file
(packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts)
with the renamed class PrismaSelectedCalendarRepository so the test imports {
PrismaSelectedCalendarRepository } from
"@calcom/features/selectedCalendar/repositories/SelectedCalendarRepository";
this will match the exported class name in PrismaSelectedCalendarRepository and
fix the failing import.
🧹 Nitpick comments (2)
packages/features/calendar-subscription/adapters/AdaptersFactory.ts (2)
19-19: Consider adding Office 365 generic calendar suffixes.The
office365_calendarentry is currently an empty array. Office 365/Outlook calendars may also have similar generic calendars (e.g., birthday calendars, holiday calendars) that should be excluded. If this is intentional (to be added later), consider adding a TODO comment. If Office 365 generic calendars are not a concern for this feature, the empty array is fine.
67-71: Consider usingObject.valuesfor cleaner iteration.The current implementation works correctly, but using
Object.valueswould be slightly more idiomatic and avoids the type cast:♻️ Optional refactor using Object.values
getGenericCalendarSuffixes(): string[] { - return Object.keys(GENERIC_CALENDAR_SUFFIXES).flatMap( - (provider) => GENERIC_CALENDAR_SUFFIXES[provider as CalendarSubscriptionProvider] - ); + return Object.values(GENERIC_CALENDAR_SUFFIXES).flat(); }
| export class PrismaSelectedCalendarRepository implements ISelectedCalendarRepository { | ||
| constructor(private prismaClient: PrismaClient) {} |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check how SelectedCalendarRepository is exported and imported across the codebase
echo "=== Checking exports from the repository file ==="
cat packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts | head -20
echo -e "\n=== Checking all imports of SelectedCalendarRepository ==="
rg -n "import.*SelectedCalendarRepository" --type=ts
echo -e "\n=== Checking if there's an index file with re-exports ==="
fd -t f "index.ts" packages/features/selectedCalendarRepository: agentic-review-benchmarks/cal.com-combined-coderabbit
Length of output: 3825
🏁 Script executed:
#!/bin/bash
# Check the re-export file at packages/lib/server/repository/selectedCalendar
echo "=== Checking re-export file ==="
cat packages/lib/server/repository/selectedCalendar.ts
echo -e "\n=== Checking what the test file actually imports ==="
cat packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts | head -10Repository: agentic-review-benchmarks/cal.com-combined-coderabbit
Length of output: 14208
Fix test import for renamed class.
The class has been renamed from SelectedCalendarRepository to PrismaSelectedCalendarRepository in packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts. The test file at packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts imports the old name and will fail:
import { SelectedCalendarRepository } from "@calcom/features/selectedCalendar/repositories/SelectedCalendarRepository";
Update the test import to use the new class name PrismaSelectedCalendarRepository.
🤖 Prompt for AI Agents
In
`@packages/features/selectedCalendar/repositories/SelectedCalendarRepository.ts`
around lines 5 - 6, Update the test that still imports the old class name:
replace the import of SelectedCalendarRepository in the test file
(packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts)
with the renamed class PrismaSelectedCalendarRepository so the test imports {
PrismaSelectedCalendarRepository } from
"@calcom/features/selectedCalendar/repositories/SelectedCalendarRepository";
this will match the exported class name in PrismaSelectedCalendarRepository and
fix the failing import.
Benchmark PR from agentic-review-benchmarks#7
Summary by CodeRabbit