mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Adjust recorder LRU cache to align with the number of entities (#88350)
* Adjust size of recorder LRU based on number of entities If there are a large number of entities the cache would get thrashed as there were more state attributes being recorded than the size of the cache. This meant we had to go back to the database to do lookups frequently when an instance has more than 2048 entities that change frequently * add a test * do not actually record 4096 states * patch target * patch target
This commit is contained in:
@@ -2075,3 +2075,18 @@ async def test_excluding_attributes_by_integration(
|
||||
expected = _state_with_context(hass, entity_id)
|
||||
expected.attributes = {"test_attr": 5}
|
||||
assert state.as_dict() == expected.as_dict()
|
||||
|
||||
|
||||
async def test_lru_increases_with_many_entities(
|
||||
recorder_mock: Recorder, hass: HomeAssistant
|
||||
) -> None:
|
||||
"""Test that the recorder's internal LRU cache increases with many entities."""
|
||||
# We do not actually want to record 4096 entities so we mock the entity count
|
||||
mock_entity_count = 4096
|
||||
with patch.object(
|
||||
hass.states, "async_entity_ids_count", return_value=mock_entity_count
|
||||
):
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=10))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert recorder_mock._state_attributes_ids.get_size() == mock_entity_count * 2
|
||||
|
||||
Reference in New Issue
Block a user