- Notifications
You must be signed in to change notification settings - Fork11.2k
fix: Conditional fetch cache#24816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
e89f9e3 Fix cache to fetch only when it's available
volnei1eb0d81 Non hierarchical feature check
volnei3c082e1 Fix tests: Add missing mock method and comprehensive CalendarCacheWra…
devin-ai-integration[bot]c39b8f4 Fix: Sanitize logging to avoid exposing PII
devin-ai-integration[bot]8133a86 Merge branch 'main' into fix/conditional-fetch-cache
volnei4a5d3cc Merge branch 'main' into fix/conditional-fetch-cache
volnei0935534 Merge branch 'main' into fix/conditional-fetch-cache
volnei52396d5 Apply suggestion from @volnei
volnei92eb1ef Merge branch 'main' into fix/conditional-fetch-cache
volneib01c1db Merge branch 'main' into fix/conditional-fetch-cache
volnei0644f04 small payload on query
volnei3188e31 Merge branch 'main' into fix/conditional-fetch-cache
volnei8d26a96 Merge branch 'main' into fix/conditional-fetch-cache
volneidf1b735 Fix missing column
volneicdd45ad Merge branch 'fix/conditional-fetch-cache' of https://github.com/calc…
volneiFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
Fix cache to fetch only when it's available
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commite89f9e3ee4e0d7c9c2d57cfe8ea4bbaf9618b61b
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
117 changes: 86 additions & 31 deletionspackages/features/calendar-subscription/lib/cache/CalendarCacheWrapper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -50,54 +50,109 @@ export class CalendarCacheWrapper implements Calendar { | ||
| } | ||
| /** | ||
| *Retrieves availability combining cache and live sources. | ||
| * | ||
| * - Calendars **with** both `syncToken` and `syncSubscribedAt` → fetched from cache. | ||
| * - Calendars **without** one of them → fetched directly from the original calendar. | ||
| * - Results are merged into a single array. | ||
| * | ||
| * @param dateFrom - Start date (ISO string) | ||
| * @param dateTo - End date (ISO string) | ||
| * @param selectedCalendars - List of calendars to retrieve availability from | ||
| * @returns Combined array of busy date ranges | ||
| */ | ||
| async getAvailability( | ||
| dateFrom: string, | ||
| dateTo: string, | ||
| selectedCalendars: IntegrationCalendar[] | ||
| ): Promise<EventBusyDate[]> { | ||
| log.debug("getAvailability (mixed cache + original)", { dateFrom, dateTo, selectedCalendars }); | ||
volnei marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if (!selectedCalendars?.length) return []; | ||
| const withSync = selectedCalendars.filter((c) => c.syncToken && c.syncSubscribedAt); | ||
| const withoutSync = selectedCalendars.filter((c) => !c.syncToken || !c.syncSubscribedAt); | ||
| const results: EventBusyDate[] = []; | ||
| // Fetch from cache for synced calendars | ||
| if (withSync.length) { | ||
| const ids = withSync.map((c) => c.id).filter((id): id is string => Boolean(id)); | ||
| const cached = await this.deps.calendarCacheEventRepository.findAllBySelectedCalendarIdsBetween( | ||
| ids, | ||
| new Date(dateFrom), | ||
| new Date(dateTo) | ||
| ); | ||
| results.push(...cached); | ||
| } | ||
| // Fetch from original calendar for unsynced ones | ||
| if (withoutSync.length) { | ||
| const original = await this.deps.originalCalendar.getAvailability(dateFrom, dateTo, withoutSync); | ||
| results.push(...original); | ||
| } | ||
| return results; | ||
| } | ||
| /** | ||
| * Retrieves availability with time zones, combining cache and live data. | ||
| * | ||
| * - Calendars **with** both `syncToken` and `syncSubscribedAt` → fetched from cache. | ||
| * - Calendars **without** one of them → fetched directly from the original calendar. | ||
| * - Results are merged into a single array with `{ start, end, timeZone }` format. | ||
| * | ||
| * @param dateFrom - Start date (ISO string) | ||
| * @param dateTo - End date (ISO string) | ||
| * @param selectedCalendars - List of calendars to retrieve availability from | ||
| * @returns Combined array of time-zone-aware availability ranges | ||
| */ | ||
| async getAvailabilityWithTimeZones( | ||
| dateFrom: string, | ||
| dateTo: string, | ||
| selectedCalendars: IntegrationCalendar[] | ||
| ): Promise<{ start: Date | string; end: Date | string; timeZone: string }[]> { | ||
| log.debug("getAvailabilityWithTimeZones (mixed cache + original)", { | ||
| dateFrom, | ||
| dateTo, | ||
| selectedCalendars, | ||
| }); | ||
| if (!selectedCalendars?.length) return []; | ||
| const withSync = selectedCalendars.filter((c) => c.syncToken && c.syncSubscribedAt); | ||
| const withoutSync = selectedCalendars.filter((c) => !c.syncToken || !c.syncSubscribedAt); | ||
| const results: { start: Date | string; end: Date | string; timeZone: string }[] = []; | ||
| // Fetch from cache for synced calendars | ||
| if (withSync.length) { | ||
| const ids = withSync.map((c) => c.id).filter((id): id is string => Boolean(id)); | ||
| const cached = await this.deps.calendarCacheEventRepository.findAllBySelectedCalendarIdsBetween( | ||
| ids, | ||
| new Date(dateFrom), | ||
| new Date(dateTo) | ||
| ); | ||
| results.push( | ||
| ...cached.map(({ start, end, timeZone }) => ({ | ||
| start, | ||
| end, | ||
| timeZone: timeZone || "UTC", | ||
| })) | ||
| ); | ||
| } | ||
| // Fetch from original calendar for unsynced ones | ||
| if (withoutSync.length) { | ||
| const original = await this.deps.originalCalendar.getAvailabilityWithTimeZones?.( | ||
| dateFrom, | ||
| dateTo, | ||
| withoutSync | ||
| ); | ||
| if (original?.length) results.push(...original); | ||
| } | ||
| return results; | ||
| } | ||
| fetchAvailabilityAndSetCache?(selectedCalendars: IntegrationCalendar[]): Promise<unknown> { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.