Avoid duplicate timestamp conversions for websocket api and recorder (#108144)
* Avoid duplicate timestamp conversions for websocket api and recorder We convert the time from datetime to timestamps one per open websocket connection and the recorder for every state update. Only do the conversion once since its ~30% of the cost of building the state diff * more * two more * two more in live history
This commit is contained in:
parent
26058bf922
commit
3d595fff13
6 changed files with 54 additions and 19 deletions
|
@ -183,9 +183,9 @@ def _state_diff(
|
|||
if old_state.state != new_state.state:
|
||||
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()
|
||||
additions[COMPRESSED_STATE_LAST_CHANGED] = new_state.last_changed_timestamp
|
||||
elif old_state.last_updated != new_state.last_updated:
|
||||
additions[COMPRESSED_STATE_LAST_UPDATED] = 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}
|
||||
if old_state_context.user_id != new_state_context.user_id:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue