Commit 253c33d
perf: (googlecalendar): batch freebusy calls by delegation credential (calcom#24332)
* perf(googlecalendar): batch freebusy calls by delegation credential
- Group selectedCalendars by delegationCredentialId before making API calls
- Make one batched freebusy query per delegation credential group
- Reduces total API calls while respecting credential boundaries
- Maintains existing caching behavior per group
- Updated both getAvailability and getAvailabilityWithTimeZones methods
- Added groupCalendarsByDelegationCredential helper method
- Handles edge case when no calendars provided but fallbackToPrimary is true
- Fixed linting issue: replaced hasOwnProperty with 'in' operator
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* test(googlecalendar): add test for delegation credential batching
- Verify calendars are grouped by delegationCredentialId
- Ensure exactly 3 API calls made for 3 delegation credential groups
- Confirm all busy times from different groups are properly returned
- Fix type-safety issues by replacing 'as any' with proper type constraints
- Fix ESLint warnings: unused variables and any types in mock functions
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix(googlecalendar): ensure fallback logic works with empty calendar groups
- Handle empty calendar groups by ensuring at least one iteration
- Add test for chunking groups larger than 50 calendars
- Verify all delegation credential batching logic works correctly
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix: fix remaining type errors from merge conflict resolution
- Changed getCacheOrFetchAvailability to getFreeBusyData in getAvailabilityWithTimeZones
- Removed orphaned merge conflict marker in test file
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix: reset test file to original PR version and update method name
- Reset CalendarService.test.ts to original PR version (0e9eb9e)
- Updated getCacheOrFetchAvailability to getFreeBusyData to match main branch
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix: reset test file to main branch version
The original PR's test file had tests for caching features that have been
removed from main. Reset to main's version to fix type errors.
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* test(googlecalendar): add tests for delegation credential batching logic
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* Revamp devin's implementation
* Remove comsoles.log
* fix(tests): update delegation credential batching tests to match reimplementation
- Remove tests for private methods that no longer exist (groupCalendarsByDelegationCredential, chunkArray)
- Update getAvailability test to verify calendar fetching without expecting multiple API calls per delegation credential
- Keep existing tests for fallback to primary calendar and non-google calendar handling
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* Remove dead code
* improve documentation
* docs: add README explaining Google Calendar availability batching feature
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* docs: translate README to English
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* docs: move README to calendar-batch package with comprehensive documentation
- Remove README from googlecalendar lib (wrong location)
- Add comprehensive README to packages/features/calendar-batch/
- Document CalendarBatchService and CalendarBatchWrapper
- Explain how getCalendar() integrates with batching
- Include architecture, data model, and performance considerations
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix: address cubic-dev-ai review comments
- Remove misleading comment from getCalendar.ts cache block
- Fix typo 'optmization' -> 'optimization' in comment
- Add comprehensive tests for CalendarBatchWrapper batching behavior
- Test separate calls for calendars without delegationCredentialId
- Test batching calendars with same delegationCredentialId
- Test chunking into groups of 50 for API limits
- Test mixed calendars handling
- Test fallbackToPrimary with empty array
- Test result flattening from batched calls
- Test pass-through methods delegation
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* fix: add shouldServeCache param to CalendarBatchWrapper and verify batching call count
- Fix CalendarBatchWrapper.getAvailability signature to match Calendar interface (add shouldServeCache param)
- Update CalendarBatchWrapper tests to pass shouldServeCache parameter
- Add integration test in CalendarService.test.ts that verifies CalendarBatchWrapper makes separate API calls for different delegationCredentialIds (call count assertion)
- This fixes the getCalendarsEvents test failures caused by signature mismatch
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* Improve CalendarBatchImplementation
* test: add shouldServeCache forwarding and order-independent batching verification tests
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* test: make CalendarBatchWrapper tests order-independent
Refactored tests to avoid relying on Promise.all execution order:
- 'should make separate calls for calendars without delegationCredentialId'
now uses set comparison instead of toHaveBeenNthCalledWith
- 'should batch calendars with the same delegationCredentialId together'
now finds calls by delegation credential instead of call order
This addresses Sean's review comment about potential flakiness due to
Promise.all not guaranteeing execution order of parallel promises.
Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>
* Remove hardcoded ID
* test: add comprehensive tests for resolveCalendarServeStrategy
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
* feat: use Promise.allSettled for partial failure handling in CalendarBatchWrapper
- Changed Promise.all to Promise.allSettled in getAvailability and getAvailabilityWithTimeZones
- Returns partial results when some batches fail instead of failing entirely
- Logs warnings for failed batches with error details
- Added tests for partial failure scenarios
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
* test: add comprehensive tests for getAvailabilityWithTimeZones
- Added batching behavior tests (separate calls, batching by delegationCredentialId, chunking)
- Added partial failure handling tests (partial results, all fail, no throw)
- Added edge case test for underlying calendar not implementing the method
- Total: 24 tests now covering both getAvailability and getAvailabilityWithTimeZones
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
* fix: add required serviceAccountKey fields to delegatedTo mock objects
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
* fix: add missing client_id and private_key to serviceAccountKey mock
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: keith@cal.com <keithwillcode@gmail.com>1 parent ed0c939 commit 253c33d
8 files changed
Lines changed: 1699 additions & 87 deletions
File tree
- packages
- app-store
- _utils
- __tests__
- googlecalendar/lib
- __tests__
- features/calendar-batch
- lib
- __tests__
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
58 | 74 | | |
59 | 75 | | |
60 | 76 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
73 | 92 | | |
74 | 93 | | |
75 | | - | |
76 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
77 | 99 | | |
Lines changed: 14 additions & 73 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | 35 | | |
44 | 36 | | |
45 | 37 | | |
| |||
120 | 112 | | |
121 | 113 | | |
122 | 114 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | 115 | | |
168 | 116 | | |
169 | 117 | | |
| |||
452 | 400 | | |
453 | 401 | | |
454 | 402 | | |
455 | | - | |
456 | | - | |
457 | | - | |
| 403 | + | |
458 | 404 | | |
459 | 405 | | |
460 | 406 | | |
| |||
471 | 417 | | |
472 | 418 | | |
473 | 419 | | |
474 | | - | |
475 | | - | |
476 | | - | |
| 420 | + | |
477 | 421 | | |
478 | 422 | | |
479 | 423 | | |
| |||
604 | 548 | | |
605 | 549 | | |
606 | 550 | | |
| 551 | + | |
607 | 552 | | |
608 | 553 | | |
609 | 554 | | |
610 | 555 | | |
611 | | - | |
| 556 | + | |
612 | 557 | | |
613 | 558 | | |
614 | 559 | | |
| |||
619 | 564 | | |
620 | 565 | | |
621 | 566 | | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
629 | 572 | | |
630 | 573 | | |
631 | 574 | | |
| |||
647 | 590 | | |
648 | 591 | | |
649 | 592 | | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
657 | 598 | | |
658 | 599 | | |
659 | 600 | | |
| |||
0 commit comments