Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
volnei merged 15 commits intomainfromfix/conditional-fetch-cache
Nov 19, 2025
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
volneiOct 31, 2025
1eb0d81
Non hierarchical feature check
volneiOct 31, 2025
3c082e1
Fix tests: Add missing mock method and comprehensive CalendarCacheWra…
devin-ai-integration[bot]Oct 31, 2025
c39b8f4
Fix: Sanitize logging to avoid exposing PII
devin-ai-integration[bot]Oct 31, 2025
8133a86
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 4, 2025
4a5d3cc
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 6, 2025
0935534
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 12, 2025
52396d5
Apply suggestion from @volnei
volneiNov 13, 2025
92eb1ef
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 14, 2025
b01c1db
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 17, 2025
0644f04
small payload on query
volneiNov 18, 2025
3188e31
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 18, 2025
8d26a96
Merge branch 'main' into fix/conditional-fetch-cache
volneiNov 18, 2025
df1b735
Fix missing column
volneiNov 18, 2025
cdd45ad
Merge branch 'fix/conditional-fetch-cache' of https://github.com/calc…
volneiNov 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Fix cache to fetch only when it's available
  • Loading branch information
@volnei
volnei committedOct 31, 2025
commite89f9e3ee4e0d7c9c2d57cfe8ea4bbaf9618b61b

Some comments aren't visible on the classic Files Changed page.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,54 +50,109 @@ export class CalendarCacheWrapper implements Calendar {
}

/**
*Override this method to use cache
*Retrieves availability combining cache and live sources.
*
* @param dateFrom
* @param dateTo
* @param selectedCalendars
* @param shouldServeCache
* - 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[]
// _shouldServeCache?: boolean
// _fallbackToPrimary?: boolean
): Promise<EventBusyDate[]> {
log.debug("getAvailability from cache", { dateFrom, dateTo, selectedCalendars });
const selectedCalendarIds = selectedCalendars.map((e) => e.id).filter((id): id is string => Boolean(id));
if (!selectedCalendarIds.length) {
return Promise.resolve([]);
log.debug("getAvailability (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: 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);
}
return this.deps.calendarCacheEventRepository.findAllBySelectedCalendarIdsBetween(
selectedCalendarIds,
new Date(dateFrom),
new Date(dateTo)
);

// 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;
}

/**
* Override this method to use cache
* 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
* @param dateTo
* @param selectedCalendars
* @returns
* @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?(
async getAvailabilityWithTimeZones(
dateFrom: string,
dateTo: string,
selectedCalendars: IntegrationCalendar[]
// _fallbackToPrimary?: boolean
): Promise<{ start: Date | string; end: Date | string; timeZone: string }[]> {
log.debug("getAvailabilityWithTimeZones from cache", { dateFrom, dateTo, selectedCalendars });
const selectedCalendarIds = selectedCalendars.map((e) => e.id).filter((id): id is string => Boolean(id));
const result = await this.deps.calendarCacheEventRepository.findAllBySelectedCalendarIdsBetween(
selectedCalendarIds,
new Date(dateFrom),
new Date(dateTo)
);
return result.map(({ start, end, timeZone }) => ({ start, end, timeZone: timeZone || "UTC" }));
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> {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp