Create bootstrap tasks eagerly (#111497)

We can avoid one event loop iteration to start the tasks here
pull/111574/head^2
J. Nick Koston 2024-02-26 18:56:16 -10:00 committed by GitHub
parent 7d9fa2f407
commit de48ad5931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 3 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations
import asyncio
from collections.abc import Coroutine
import contextlib
from datetime import timedelta
import logging
@ -51,6 +50,7 @@ from .setup import (
async_set_domains_to_be_loaded,
async_setup_component,
)
from .util.async_ import create_eager_task
from .util.logging import async_activate_log_queue_handler
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
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] = []
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)
needed_requirements.update(itg.requirements)
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 there are dependencies, try to preload all
@ -712,6 +718,7 @@ async def _async_resolve_domains_to_setup(
hass.async_create_background_task(
requirements.async_load_installed_versions(hass, needed_requirements),
"check installed requirements",
eager_start=True,
)
# 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
@ -726,6 +733,7 @@ async def _async_resolve_domains_to_setup(
hass.async_create_background_task(
translation.async_load_integrations(hass, {*BASE_PLATFORMS, *domains_to_setup}),
"load translations",
eager_start=True,
)
return domains_to_setup, integration_cache