perf: cache fetched events within a refresh cycle

FeedEngine calls fetchContext then fetchItems with the same
context. Cache events by context.time reference to avoid
duplicate CalDAV round-trips.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-02-14 15:36:36 +00:00
parent e8ba49d7bb
commit 13c411c842
2 changed files with 42 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ export class CalendarSource implements FeedSource<CalendarFeedItem> {
private readonly injectedClient: CalendarDAVClient | null
private davClient: CalendarDAVClient | null = null
private lastAccessToken: string | null = null
private cachedEvents: { time: Date; events: CalendarEventData[] } | null = null
constructor(
credentialProvider: CalendarCredentialProvider,
@@ -94,6 +95,10 @@ export class CalendarSource implements FeedSource<CalendarFeedItem> {
}
private async fetchEvents(context: Context): Promise<CalendarEventData[]> {
if (this.cachedEvents && this.cachedEvents.time === context.time) {
return this.cachedEvents.events
}
const credentials = await this.credentialProvider.fetchCredentials(this.userId)
if (!credentials) {
return []
@@ -134,6 +139,7 @@ export class CalendarSource implements FeedSource<CalendarFeedItem> {
}
}
this.cachedEvents = { time: context.time, events: allEvents }
return allEvents
}