mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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,6 +1,5 @@
|
|||||||
"""Library for working with CalDAV api."""
|
"""Library for working with CalDAV api."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import caldav
|
import caldav
|
||||||
|
|
||||||
@ -13,20 +12,13 @@ async def async_get_calendars(
|
|||||||
"""Get all calendars that support the specified component."""
|
"""Get all calendars that support the specified component."""
|
||||||
|
|
||||||
def _get_calendars() -> list[caldav.Calendar]:
|
def _get_calendars() -> list[caldav.Calendar]:
|
||||||
return client.principal().calendars()
|
return [
|
||||||
|
calendar
|
||||||
calendars = await hass.async_add_executor_job(_get_calendars)
|
for calendar in client.principal().calendars()
|
||||||
components_results = await asyncio.gather(
|
if component in calendar.get_supported_components()
|
||||||
*[
|
|
||||||
hass.async_add_executor_job(calendar.get_supported_components)
|
|
||||||
for calendar in calendars
|
|
||||||
]
|
]
|
||||||
)
|
|
||||||
return [
|
return await hass.async_add_executor_job(_get_calendars)
|
||||||
calendar
|
|
||||||
for calendar, supported_components in zip(calendars, components_results)
|
|
||||||
if component in supported_components
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_attr_value(obj: caldav.CalendarObjectResource, attribute: str) -> str | None:
|
def get_attr_value(obj: caldav.CalendarObjectResource, attribute: str) -> str | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user