Skip to content

Commit

Permalink
Remove as_compressed_state cache (#93169)
Browse files Browse the repository at this point in the history
* Remove as_compressed_state cache

All calls to as_compressed_state are now covered by a higher level
JSON cache so there is no need to store these in memory anymore

* Remove as_compressed_state cache

All calls to as_compressed_state are now covered by a higher level
JSON cache so there is no need to store these in memory anymore
  • Loading branch information
bdraco committed May 16, 2023
1 parent e949344 commit bf16f6b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 7 deletions.
5 changes: 0 additions & 5 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,6 @@ class State:
"domain",
"object_id",
"_as_dict",
"_as_compressed_state",
"_as_dict_json",
"_as_compressed_state_json",
)
Expand Down Expand Up @@ -1262,7 +1261,6 @@ def __init__(
self.context = context or Context()
self.domain, self.object_id = split_entity_id(self.entity_id)
self._as_dict: ReadOnlyDict[str, Collection[Any]] | None = None
self._as_compressed_state: dict[str, Any] | None = None
self._as_dict_json: str | None = None
self._as_compressed_state_json: str | None = None

Expand Down Expand Up @@ -1312,8 +1310,6 @@ def as_compressed_state(self) -> dict[str, Any]:
Sends c (context) as a string if it only contains an id.
"""
if self._as_compressed_state:
return self._as_compressed_state
state_context = self.context
if state_context.parent_id is None and state_context.user_id is None:
context: dict[str, Any] | str = state_context.id
Expand All @@ -1329,7 +1325,6 @@ def as_compressed_state(self) -> dict[str, Any]:
compressed_state[COMPRESSED_STATE_LAST_UPDATED] = dt_util.utc_to_timestamp(
self.last_updated
)
self._as_compressed_state = compressed_state
return compressed_state

def as_compressed_state_json(self) -> str:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def test_state_as_compressed_state() -> None:
assert as_compressed_state == expected
# 2nd time to verify cache
assert state.as_compressed_state() == expected
assert state.as_compressed_state() is as_compressed_state


def test_state_as_compressed_state_unique_last_updated() -> None:
Expand All @@ -538,7 +537,6 @@ def test_state_as_compressed_state_unique_last_updated() -> None:
assert as_compressed_state == expected
# 2nd time to verify cache
assert state.as_compressed_state() == expected
assert state.as_compressed_state() is as_compressed_state


def test_state_as_compressed_state_json() -> None:
Expand Down

0 comments on commit bf16f6b

Please sign in to comment.