mirror of https://github.com/home-assistant/core
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 loading
This commit is contained in:
parent
e38836b6e1
commit
8806c3dd20
|
@ -143,25 +143,18 @@ def _build_resources(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_component_strings(
|
async def _async_get_component_strings(
|
||||||
hass: HomeAssistant, language: str, components: set[str]
|
hass: HomeAssistant,
|
||||||
|
language: str,
|
||||||
|
components: set[str],
|
||||||
|
integrations: dict[str, Integration],
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Load translations."""
|
"""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] = {}
|
translations: dict[str, Any] = {}
|
||||||
|
|
||||||
# Determine paths of missing components/platforms
|
# Determine paths of missing components/platforms
|
||||||
files_to_load = {}
|
files_to_load = {}
|
||||||
for loaded in components:
|
for loaded in components:
|
||||||
parts = loaded.split(".")
|
domain = loaded.rpartition(".")[-1]
|
||||||
domain = parts[-1]
|
|
||||||
integration = integrations[domain]
|
integration = integrations[domain]
|
||||||
|
|
||||||
path = component_translation_path(loaded, language, integration)
|
path = component_translation_path(loaded, language, integration)
|
||||||
|
@ -228,9 +221,18 @@ class _TranslationCache:
|
||||||
)
|
)
|
||||||
# Fetch the English resources, as a fallback for missing keys
|
# Fetch the English resources, as a fallback for missing keys
|
||||||
languages = [LOCALE_EN] if language == LOCALE_EN else [LOCALE_EN, language]
|
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(
|
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
|
for lang in languages
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in New Issue