Preload storage for integrations we know we are going to setup (#114192)

This commit is contained in:
J. Nick Koston
2024-03-25 15:49:54 -10:00
committed by GitHub
parent 345fa75562
commit cabc4f797a
7 changed files with 527 additions and 31 deletions

View File

@@ -78,6 +78,7 @@ from .helpers import (
translation,
)
from .helpers.dispatcher import async_dispatcher_send
from .helpers.storage import get_internal_store_manager
from .helpers.system_info import async_get_system_info
from .helpers.typing import ConfigType
from .setup import (
@@ -203,6 +204,27 @@ SETUP_ORDER = (
("debugger", DEBUGGER_INTEGRATIONS),
)
#
# Storage keys we are likely to load during startup
# in order of when we expect to load them.
#
# If they do not exist they will not be loaded
#
PRELOAD_STORAGE = [
"core.network",
"http.auth",
"image",
"lovelace_dashboards",
"lovelace_resources",
"core.uuid",
"lovelace.map",
"bluetooth.passive_update_processor",
"bluetooth.remote_scanners",
"assist_pipeline.pipelines",
"core.analytics",
"auth_module.totp",
]
async def async_setup_hass(
runtime_config: RuntimeConfig,
@@ -346,6 +368,7 @@ async def async_load_base_functionality(hass: core.HomeAssistant) -> None:
entity.async_setup(hass)
template.async_setup(hass)
await asyncio.gather(
create_eager_task(get_internal_store_manager(hass).async_initialize()),
create_eager_task(area_registry.async_load(hass)),
create_eager_task(category_registry.async_load(hass)),
create_eager_task(device_registry.async_load(hass)),
@@ -840,6 +863,17 @@ async def _async_resolve_domains_to_setup(
eager_start=True,
)
# Preload storage for all integrations we are going to set up
# so we do not have to wait for it to be loaded when we need it
# in the setup process.
hass.async_create_background_task(
get_internal_store_manager(hass).async_preload(
[*PRELOAD_STORAGE, *domains_to_setup]
),
"preload storage",
eager_start=True,
)
return domains_to_setup, integration_cache