mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Avoid copying translations for single components (#108645)
This commit is contained in:
parent
852e4c21c6
commit
f883f721c8
@ -218,8 +218,14 @@ class _TranslationCache:
|
|||||||
if components_to_load := components - loaded:
|
if components_to_load := components - loaded:
|
||||||
await self._async_load(language, components_to_load)
|
await self._async_load(language, components_to_load)
|
||||||
|
|
||||||
result: dict[str, str] = {}
|
|
||||||
category_cache = self.cache.get(language, {}).get(category, {})
|
category_cache = self.cache.get(language, {}).get(category, {})
|
||||||
|
# If only one component was requested, return it directly
|
||||||
|
# to avoid merging the dictionaries and keeping additional
|
||||||
|
# copies of the same data in memory.
|
||||||
|
if len(components) == 1 and (component := next(iter(components))):
|
||||||
|
return category_cache.get(component, {})
|
||||||
|
|
||||||
|
result: dict[str, str] = {}
|
||||||
for component in components.intersection(category_cache):
|
for component in components.intersection(category_cache):
|
||||||
result.update(category_cache[component])
|
result.update(category_cache[component])
|
||||||
return result
|
return result
|
||||||
@ -298,7 +304,6 @@ class _TranslationCache:
|
|||||||
"""Extract resources into the cache."""
|
"""Extract resources into the cache."""
|
||||||
resource: dict[str, Any] | str
|
resource: dict[str, Any] | str
|
||||||
cached = self.cache.setdefault(language, {})
|
cached = self.cache.setdefault(language, {})
|
||||||
|
|
||||||
categories: set[str] = set()
|
categories: set[str] = set()
|
||||||
for resource in translation_strings.values():
|
for resource in translation_strings.values():
|
||||||
categories.update(resource)
|
categories.update(resource)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user