Speed up loading non-english language translations (#88553)
Speed up loading non-english languages We called async_get_integrations in each gathered task instead of once for both languages we were loadingpull/87823/head^2
parent
e38836b6e1
commit
8806c3dd20
|
@ -143,25 +143,18 @@ def _build_resources(
|
|||
}
|
||||
|
||||
|
||||
async def async_get_component_strings(
|
||||
hass: HomeAssistant, language: str, components: set[str]
|
||||
async def _async_get_component_strings(
|
||||
hass: HomeAssistant,
|
||||
language: str,
|
||||
components: set[str],
|
||||
integrations: dict[str, Integration],
|
||||
) -> dict[str, Any]:
|
||||
"""Load translations."""
|
||||
domains = list({loaded.rpartition(".")[-1] for loaded in components})
|
||||
|
||||
integrations: dict[str, Integration] = {}
|
||||
ints_or_excs = await async_get_integrations(hass, domains)
|
||||
for domain, int_or_exc in ints_or_excs.items():
|
||||
if isinstance(int_or_exc, Exception):
|
||||
raise int_or_exc
|
||||
integrations[domain] = int_or_exc
|
||||
translations: dict[str, Any] = {}
|
||||
|
||||
# Determine paths of missing components/platforms
|
||||
files_to_load = {}
|
||||
for loaded in components:
|
||||
parts = loaded.split(".")
|
||||
domain = parts[-1]
|
||||
domain = loaded.rpartition(".")[-1]
|
||||
integration = integrations[domain]
|
||||
|
||||
path = component_translation_path(loaded, language, integration)
|
||||
|
@ -228,9 +221,18 @@ class _TranslationCache:
|
|||
)
|
||||
# Fetch the English resources, as a fallback for missing keys
|
||||
languages = [LOCALE_EN] if language == LOCALE_EN else [LOCALE_EN, language]
|
||||
|
||||
integrations: dict[str, Integration] = {}
|
||||
domains = list({loaded.rpartition(".")[-1] for loaded in components})
|
||||
ints_or_excs = await async_get_integrations(self.hass, domains)
|
||||
for domain, int_or_exc in ints_or_excs.items():
|
||||
if isinstance(int_or_exc, Exception):
|
||||
raise int_or_exc
|
||||
integrations[domain] = int_or_exc
|
||||
|
||||
for translation_strings in await asyncio.gather(
|
||||
*(
|
||||
async_get_component_strings(self.hass, lang, components)
|
||||
_async_get_component_strings(self.hass, lang, components, integrations)
|
||||
for lang in languages
|
||||
)
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue