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:
J. Nick Koston 2024-03-02 16:53:51 -10:00 committed by GitHub
parent 08c96efebe
commit ea9c969d15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: