Reduce size of load query to prime event_types and states_meta at startup (#89677)

This commit is contained in:
J. Nick Koston 2023-03-14 10:31:31 -10:00 committed by GitHub
parent c2c809682a
commit 0630b7b962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions

View file

@ -793,13 +793,13 @@ class Recorder(threading.Thread):
until its primed.
"""
assert self.event_session is not None
if hashes := [
if hashes := {
StateAttributes.hash_shared_attrs_bytes(shared_attrs_bytes)
for event in events
if (
shared_attrs_bytes := self._serialize_state_attributes_from_event(event)
)
]:
}:
with self.event_session.no_autoflush:
for hash_chunk in chunked(hashes, SQLITE_MAX_BIND_VARS):
for id_, shared_attrs in self.event_session.execute(
@ -815,11 +815,11 @@ class Recorder(threading.Thread):
the data in the database for every event until its primed.
"""
assert self.event_session is not None
if hashes := [
if hashes := {
EventData.hash_shared_data_bytes(shared_event_bytes)
for event in events
if (shared_event_bytes := self._serialize_event_data_from_event(event))
]:
}:
with self.event_session.no_autoflush:
for hash_chunk in chunked(hashes, SQLITE_MAX_BIND_VARS):
for id_, shared_data in self.event_session.execute(