mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Reduce time to reload yaml and check configuration (#38469)
* Reduce time to reload yaml and check configuration We spend a significant amount of time compiling templates that we have already compiled. Use an LRU cache to avoid re-compiling templates that we frequently use. * pylint * switch to WeakValueDictionary * preen
This commit is contained in:
@@ -1885,3 +1885,30 @@ def test_urlencode(hass):
|
||||
hass,
|
||||
)
|
||||
assert tpl.async_render() == "the%20quick%20brown%20fox%20%3D%20true"
|
||||
|
||||
|
||||
async def test_cache_garbage_collection():
|
||||
"""Test caching a template."""
|
||||
template_string = (
|
||||
"{% set dict = {'foo': 'x&y', 'bar': 42} %} {{ dict | urlencode }}"
|
||||
)
|
||||
tpl = template.Template((template_string),)
|
||||
tpl.ensure_valid()
|
||||
assert template._NO_HASS_ENV.template_cache.get(
|
||||
template_string
|
||||
) # pylint: disable=protected-access
|
||||
|
||||
tpl2 = template.Template((template_string),)
|
||||
tpl2.ensure_valid()
|
||||
assert template._NO_HASS_ENV.template_cache.get(
|
||||
template_string
|
||||
) # pylint: disable=protected-access
|
||||
|
||||
del tpl
|
||||
assert template._NO_HASS_ENV.template_cache.get(
|
||||
template_string
|
||||
) # pylint: disable=protected-access
|
||||
del tpl2
|
||||
assert not template._NO_HASS_ENV.template_cache.get(
|
||||
template_string
|
||||
) # pylint: disable=protected-access
|
||||
|
||||
Reference in New Issue
Block a user