From 1e545950845fb486729ed0a5023cc8883430f513 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 20 Mar 2024 13:40:23 -1000 Subject: [PATCH] Use faster time compare in history and live logbook (#113897) --- homeassistant/components/history/websocket_api.py | 5 ++++- homeassistant/components/logbook/websocket_api.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py index 27e490dd8d4..462d8464229 100644 --- a/homeassistant/components/history/websocket_api.py +++ b/homeassistant/components/history/websocket_api.py @@ -331,11 +331,14 @@ async def _async_events_consumer( no_attributes: bool, ) -> None: """Stream events from the queue.""" + subscriptions_setup_complete_timestamp = ( + subscriptions_setup_complete_time.timestamp() + ) while True: events: list[Event] = [await stream_queue.get()] # If the event is older than the last db # event we already sent it so we skip it. - if events[0].time_fired <= subscriptions_setup_complete_time: + if events[0].time_fired_timestamp <= subscriptions_setup_complete_timestamp: continue # We sleep for the EVENT_COALESCE_TIME so # we can group events together to minimize diff --git a/homeassistant/components/logbook/websocket_api.py b/homeassistant/components/logbook/websocket_api.py index b7555d91241..cac58971cde 100644 --- a/homeassistant/components/logbook/websocket_api.py +++ b/homeassistant/components/logbook/websocket_api.py @@ -222,11 +222,14 @@ async def _async_events_consumer( event_processor: EventProcessor, ) -> None: """Stream events from the queue.""" + subscriptions_setup_complete_timestamp = ( + subscriptions_setup_complete_time.timestamp() + ) while True: events: list[Event] = [await stream_queue.get()] # If the event is older than the last db # event we already sent it so we skip it. - if events[0].time_fired <= subscriptions_setup_complete_time: + if events[0].time_fired_timestamp <= subscriptions_setup_complete_timestamp: continue # We sleep for the EVENT_COALESCE_TIME so # we can group events together to minimize