From 1c431aa7bdcf33ce4290485895e7f7f57f3467b5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Oct 2020 02:31:17 -0500 Subject: [PATCH] Set created field when creating db events and states (#41523) Avoids thousands of utcnow calls when the session is commited on busy systems to fill in the field default. --- homeassistant/components/recorder/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index 3cfa2d68d53..65cb02d9ab1 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -393,6 +393,7 @@ class Recorder(threading.Thread): dbevent = Events.from_event(event, event_data="{}") else: dbevent = Events.from_event(event) + dbevent.created = event.time_fired self.event_session.add(dbevent) except (TypeError, ValueError): _LOGGER.warning("Event is not JSON serializable: %s", event) @@ -409,6 +410,7 @@ class Recorder(threading.Thread): if not has_new_state: dbstate.state = None dbstate.event = dbevent + dbstate.created = event.time_fired self.event_session.add(dbstate) if has_new_state: self._old_states[dbstate.entity_id] = dbstate