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") _logger.debug("calendars")
return [str(cal.name) for cal in cls.principal.calendars()] return [str(cal.name) for cal in cls.principal.calendars()]
@classmethod
@AsyncTTL( @AsyncTTL(
time_to_live=SETTINGS.caldav.cache_ttl, time_to_live=SETTINGS.caldav.cache_ttl,
maxsize=SETTINGS.caldav.cache_size, maxsize=SETTINGS.caldav.cache_size,
skip_args=1, skip_args=1,
) )
@asyncify @asyncify
@classmethod
def get_calendar(cls, calendar_name: str) -> Calendar: def get_calendar(cls, calendar_name: str) -> Calendar:
""" """
Get a calendar by name using the CalDAV principal object. Get a calendar by name using the CalDAV principal object.
@ -62,6 +62,12 @@ class CalDAV:
return cls.principal.calendar(calendar_name) return cls.principal.calendar(calendar_name)
@classmethod @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]: def get_events(cls, calendar_name: str, cfg: Config) -> list[CalEvent]:
""" """
Get a sorted list of events by CalDAV calendar name. 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]: for cal_prefix in cfg.calendar.aggregates[name]:
cal_name = await LM_CALENDARS.getter.func(cal_prefix) 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) return sorted(events)

View file

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