* 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
parent
6f56ff8f87
commit
6b4cea2f30
|
@ -208,17 +208,33 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
.filter((e) => e.integration === this.integrationName)
|
.filter((e) => e.integration === this.integrationName)
|
||||||
.map((e) => e.externalId);
|
.map((e) => e.externalId);
|
||||||
|
|
||||||
const events = [];
|
if (selectedCalendarIds.length == 0 && selectedCalendars.length > 0) {
|
||||||
|
// Only calendars of other integrations selected
|
||||||
for (const calId of selectedCalendarIds) {
|
return Promise.resolve([]);
|
||||||
const calEvents = await this.getEvents(calId, dateFrom, dateTo);
|
|
||||||
|
|
||||||
for (const ev of calEvents) {
|
|
||||||
events.push({ start: ev.startDate, end: ev.endDate });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
} catch (reason) {
|
||||||
log.error(reason);
|
log.error(reason);
|
||||||
throw 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 {
|
try {
|
||||||
const objects = await fetchCalendarObjects({
|
const objects = await fetchCalendarObjects({
|
||||||
calendar: {
|
calendar: {
|
||||||
|
|
Loading…
Reference in New Issue