mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user