refac: asyncify CalDAV.get_events

This commit is contained in:
Jörn-Michael Miehe 2023-10-26 18:04:03 +02:00
parent cc96889bc4
commit b6798df29c
3 changed files with 9 additions and 3 deletions

View file

@ -47,13 +47,13 @@ class CalDAV:
_logger.debug("calendars")
return [str(cal.name) for cal in cls.principal.calendars()]
@classmethod
@AsyncTTL(
time_to_live=SETTINGS.caldav.cache_ttl,
maxsize=SETTINGS.caldav.cache_size,
skip_args=1,
)
@asyncify
@classmethod
def get_calendar(cls, calendar_name: str) -> Calendar:
"""
Get a calendar by name using the CalDAV principal object.
@ -62,6 +62,12 @@ class CalDAV:
return cls.principal.calendar(calendar_name)
@classmethod
@AsyncTTL(
time_to_live=SETTINGS.caldav.cache_ttl,
maxsize=SETTINGS.caldav.cache_size,
skip_args=1,
)
@asyncify
def get_events(cls, calendar_name: str, cfg: Config) -> list[CalEvent]:
"""
Get a sorted list of events by CalDAV calendar name.

View file

@ -58,6 +58,6 @@ async def get_aggregate_calendar(
for cal_prefix in cfg.calendar.aggregates[name]:
cal_name = await LM_CALENDARS.getter.func(cal_prefix)
events.extend(CalDAV.get_events(cal_name, cfg))
events.extend(await CalDAV.get_events(cal_name, cfg))
return sorted(events)

View file

@ -52,7 +52,7 @@ async def get_calendar(
name: str = Depends(LM_CALENDARS.getter.func),
cfg: Config = Depends(get_config),
) -> list[CalEvent]:
return CalDAV.get_events(name, cfg)
return await CalDAV.get_events(name, cfg)
@router.get("/config")