Create an index on the states table to help hass startup time (#8255)
This commit is contained in:
parent
8fb49e8687
commit
da44f80b32
2 changed files with 6 additions and 2 deletions
|
@ -64,6 +64,8 @@ def _apply_update(engine, new_version):
|
||||||
# Create indexes for states
|
# Create indexes for states
|
||||||
_create_index(engine, "states", "ix_states_last_updated")
|
_create_index(engine, "states", "ix_states_last_updated")
|
||||||
_create_index(engine, "states", "ix_states_entity_id_created")
|
_create_index(engine, "states", "ix_states_entity_id_created")
|
||||||
|
elif new_version == 3:
|
||||||
|
_create_index(engine, "states", "ix_states_created_domain")
|
||||||
else:
|
else:
|
||||||
raise ValueError("No schema migration defined for version {}"
|
raise ValueError("No schema migration defined for version {}"
|
||||||
.format(new_version))
|
.format(new_version))
|
||||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.remote import JSONEncoder
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
SCHEMA_VERSION = 2
|
SCHEMA_VERSION = 3
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -75,7 +75,9 @@ class States(Base): # type: ignore
|
||||||
Index('states__significant_changes',
|
Index('states__significant_changes',
|
||||||
'domain', 'last_updated', 'entity_id'),
|
'domain', 'last_updated', 'entity_id'),
|
||||||
Index('ix_states_entity_id_created',
|
Index('ix_states_entity_id_created',
|
||||||
'entity_id', 'created'),)
|
'entity_id', 'created'),
|
||||||
|
Index('ix_states_created_domain',
|
||||||
|
'created', 'domain'),)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_event(event):
|
def from_event(event):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue