Copy of #560 Parallel CalDav (#621)

* Make the caldav queries run in parallel when querying availability

* improvements to caldav operations

run queries in parallel

if no selected calendars get availability from all calendars

* fix: busyTimes not properly resolved

Co-authored-by: Kuba Orlik <kontakt@kuba-orlik.name>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
pull/616/head^2
Femi Odugbesan 2021-09-09 14:03:07 -05:00 committed by GitHub
parent 6f56ff8f87
commit 6b4cea2f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 10 deletions

View File

@ -208,17 +208,33 @@ export class CalDavCalendar implements CalendarApiAdapter {
.filter((e) => e.integration === this.integrationName)
.map((e) => e.externalId);
const events = [];
for (const calId of selectedCalendarIds) {
const calEvents = await this.getEvents(calId, dateFrom, dateTo);
for (const ev of calEvents) {
events.push({ start: ev.startDate, end: ev.endDate });
}
if (selectedCalendarIds.length == 0 && selectedCalendars.length > 0) {
// Only calendars of other integrations selected
return Promise.resolve([]);
}
return events;
return (
selectedCalendarIds.length === 0
? this.listCalendars().then((calendars) => calendars.map((calendar) => calendar.externalId))
: Promise.resolve(selectedCalendarIds)
).then(async (ids: string[]) => {
if (ids.length === 0) {
return Promise.resolve([]);
}
return (
await Promise.all(
ids.map(async (calId) => {
return (await this.getEvents(calId, dateFrom, dateTo)).map((event) => {
return {
start: event.startDate,
end: event.endDate,
};
});
})
)
).flatMap((event) => event);
});
} catch (reason) {
log.error(reason);
throw reason;
@ -249,7 +265,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
}
}
async getEvents(calId: string, dateFrom: string | null, dateTo: string | null): Promise<unknown> {
async getEvents(calId: string, dateFrom: string | null, dateTo: string | null): Promise<unknown[]> {
try {
const objects = await fetchCalendarObjects({
calendar: {