refac: asyncify CalDAV.get_events
This commit is contained in:
parent
cc96889bc4
commit
b6798df29c
3 changed files with 9 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue