Improve performance of websocket_api _state_diff_event (#141696)

We can use last_updated_timestamp for the compare since its always
calculated when the state is created and comparing floats is
much faster than datetime objects
This commit is contained in:
J. Nick Koston 2025-03-28 13:58:12 -10:00 committed by GitHub
parent ba8f69d956
commit d6b48003b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -207,7 +207,7 @@ def _state_diff_event(
additions[COMPRESSED_STATE_STATE] = new_state.state
if old_state.last_changed != new_state.last_changed:
additions[COMPRESSED_STATE_LAST_CHANGED] = new_state.last_changed_timestamp
elif old_state.last_updated != new_state.last_updated:
elif old_state.last_updated_timestamp != new_state.last_updated_timestamp:
additions[COMPRESSED_STATE_LAST_UPDATED] = new_state.last_updated_timestamp
if old_state_context.parent_id != new_state_context.parent_id:
additions[COMPRESSED_STATE_CONTEXT] = {"parent_id": new_state_context.parent_id}