Fix executor being overloaded in caldav (#112084)
Migrate to using a single executor job instead of creating one per calendar. If the user had a lot of calendars the executor would get overloaded
This commit is contained in:
parent
08c96efebe
commit
ea9c969d15
1 changed files with 6 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
|||
"""Library for working with CalDAV api."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import caldav
|
||||
|
||||
|
@ -13,20 +12,13 @@ async def async_get_calendars(
|
|||
"""Get all calendars that support the specified component."""
|
||||
|
||||
def _get_calendars() -> list[caldav.Calendar]:
|
||||
return client.principal().calendars()
|
||||
|
||||
calendars = await hass.async_add_executor_job(_get_calendars)
|
||||
components_results = await asyncio.gather(
|
||||
*[
|
||||
hass.async_add_executor_job(calendar.get_supported_components)
|
||||
for calendar in calendars
|
||||
return [
|
||||
calendar
|
||||
for calendar in client.principal().calendars()
|
||||
if component in calendar.get_supported_components()
|
||||
]
|
||||
)
|
||||
return [
|
||||
calendar
|
||||
for calendar, supported_components in zip(calendars, components_results)
|
||||
if component in supported_components
|
||||
]
|
||||
|
||||
return await hass.async_add_executor_job(_get_calendars)
|
||||
|
||||
|
||||
def get_attr_value(obj: caldav.CalendarObjectResource, attribute: str) -> str | None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue