mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Create bootstrap tasks eagerly (#111497)
We can avoid one event loop iteration to start the tasks here
This commit is contained in:
parent
7d9fa2f407
commit
de48ad5931
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Coroutine
|
|
||||||
import contextlib
|
import contextlib
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
@ -51,6 +50,7 @@ from .setup import (
|
|||||||
async_set_domains_to_be_loaded,
|
async_set_domains_to_be_loaded,
|
||||||
async_setup_component,
|
async_setup_component,
|
||||||
)
|
)
|
||||||
|
from .util.async_ import create_eager_task
|
||||||
from .util.logging import async_activate_log_queue_handler
|
from .util.logging import async_activate_log_queue_handler
|
||||||
from .util.package import async_get_user_site, is_virtual_env
|
from .util.package import async_get_user_site, is_virtual_env
|
||||||
|
|
||||||
@ -667,7 +667,7 @@ async def _async_resolve_domains_to_setup(
|
|||||||
to_get = old_to_resolve
|
to_get = old_to_resolve
|
||||||
|
|
||||||
manifest_deps: set[str] = set()
|
manifest_deps: set[str] = set()
|
||||||
resolve_dependencies_tasks: list[Coroutine[Any, Any, bool]] = []
|
resolve_dependencies_tasks: list[asyncio.Task[bool]] = []
|
||||||
integrations_to_process: list[loader.Integration] = []
|
integrations_to_process: list[loader.Integration] = []
|
||||||
|
|
||||||
for domain, itg in (await loader.async_get_integrations(hass, to_get)).items():
|
for domain, itg in (await loader.async_get_integrations(hass, to_get)).items():
|
||||||
@ -679,7 +679,13 @@ async def _async_resolve_domains_to_setup(
|
|||||||
manifest_deps.update(itg.after_dependencies)
|
manifest_deps.update(itg.after_dependencies)
|
||||||
needed_requirements.update(itg.requirements)
|
needed_requirements.update(itg.requirements)
|
||||||
if not itg.all_dependencies_resolved:
|
if not itg.all_dependencies_resolved:
|
||||||
resolve_dependencies_tasks.append(itg.resolve_dependencies())
|
resolve_dependencies_tasks.append(
|
||||||
|
create_eager_task(
|
||||||
|
itg.resolve_dependencies(),
|
||||||
|
name=f"resolve dependencies {domain}",
|
||||||
|
loop=hass.loop,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if unseen_deps := manifest_deps - integration_cache.keys():
|
if unseen_deps := manifest_deps - integration_cache.keys():
|
||||||
# If there are dependencies, try to preload all
|
# If there are dependencies, try to preload all
|
||||||
@ -712,6 +718,7 @@ async def _async_resolve_domains_to_setup(
|
|||||||
hass.async_create_background_task(
|
hass.async_create_background_task(
|
||||||
requirements.async_load_installed_versions(hass, needed_requirements),
|
requirements.async_load_installed_versions(hass, needed_requirements),
|
||||||
"check installed requirements",
|
"check installed requirements",
|
||||||
|
eager_start=True,
|
||||||
)
|
)
|
||||||
# Start loading translations for all integrations we are going to set up
|
# Start loading translations for all integrations we are going to set up
|
||||||
# in the background so they are ready when we need them. This avoids a
|
# in the background so they are ready when we need them. This avoids a
|
||||||
@ -726,6 +733,7 @@ async def _async_resolve_domains_to_setup(
|
|||||||
hass.async_create_background_task(
|
hass.async_create_background_task(
|
||||||
translation.async_load_integrations(hass, {*BASE_PLATFORMS, *domains_to_setup}),
|
translation.async_load_integrations(hass, {*BASE_PLATFORMS, *domains_to_setup}),
|
||||||
"load translations",
|
"load translations",
|
||||||
|
eager_start=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
return domains_to_setup, integration_cache
|
return domains_to_setup, integration_cache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user