mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Reduce overhead to fetch integrations (#93767)
We call this path over and over during startup and most of the time the integration is already loaded. We want that case to be the short path
This commit is contained in:
parent
1ea202a5bc
commit
53fe74e055
@ -891,14 +891,15 @@ async def async_get_integrations(
|
||||
results: dict[str, Integration | Exception] = {}
|
||||
needed: dict[str, asyncio.Future[None]] = {}
|
||||
in_progress: dict[str, asyncio.Future[None]] = {}
|
||||
if TYPE_CHECKING:
|
||||
cache = cast(dict[str, Integration | asyncio.Future[None]], cache)
|
||||
for domain in domains:
|
||||
int_or_fut: Integration | asyncio.Future[None] | None = cache.get(
|
||||
domain, _UNDEF
|
||||
)
|
||||
if isinstance(int_or_fut, asyncio.Future):
|
||||
in_progress[domain] = int_or_fut
|
||||
int_or_fut = cache.get(domain, _UNDEF)
|
||||
# Integration is never subclassed, so we can check for type
|
||||
if type(int_or_fut) is Integration: # pylint: disable=unidiomatic-typecheck
|
||||
results[domain] = int_or_fut
|
||||
elif int_or_fut is not _UNDEF:
|
||||
results[domain] = cast(Integration, int_or_fut)
|
||||
in_progress[domain] = cast(asyncio.Future[None], int_or_fut)
|
||||
elif "." in domain:
|
||||
results[domain] = ValueError(f"Invalid domain {domain}")
|
||||
else:
|
||||
@ -915,8 +916,10 @@ async def async_get_integrations(
|
||||
else:
|
||||
results[domain] = cast(Integration, int_or_fut)
|
||||
|
||||
if not needed:
|
||||
return results
|
||||
|
||||
# First we look for custom components
|
||||
if needed:
|
||||
# Instead of using resolve_from_root we use the cache of custom
|
||||
# components to find the integration.
|
||||
custom = await async_get_custom_components(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user