Avoid event data serialization during recorder that we throw away (#41217)
We currently serialize the event data for state change events and then replace it because we save the state in the states table. Since the old state and new state are both contains in the event the cost of serializing the data has a noticable impact when there are many state changed events.
This commit is contained in:
1 parent
44580b1c07
commit
20a136e2a1
3 files changed
+19
-4
No files matched your search
@@ -60,11 +60,11 @@ class Events(Base): # type: ignore
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_event(event):
|
||||
def from_event(event, event_data=None):
|
||||
"""Create an event database object from a native event."""
|
||||
return Events(
|
||||
event_type=event.event_type,
|
||||
event_data=json.dumps(event.data, cls=JSONEncoder),
|
||||
event_data=event_data or json.dumps(event.data, cls=JSONEncoder),
|
||||
origin=str(event.origin),
|
||||
time_fired=event.time_fired,
|
||||
context_id=event.context.id,
|
||||
|
||||
Reference in new issue
Block a user