Create an index on the states table to help hass startup time (#8255)

This commit is contained in:
Mike Megally 2017-07-01 14:10:17 -07:00 committed by Paulus Schoutsen
parent 8fb49e8687
commit da44f80b32
2 changed files with 6 additions and 2 deletions

View file

@ -64,6 +64,8 @@ def _apply_update(engine, new_version):
# Create indexes for states
_create_index(engine, "states", "ix_states_last_updated")
_create_index(engine, "states", "ix_states_entity_id_created")
elif new_version == 3:
_create_index(engine, "states", "ix_states_created_domain")
else:
raise ValueError("No schema migration defined for version {}"
.format(new_version))

View file

@ -16,7 +16,7 @@ from homeassistant.remote import JSONEncoder
# pylint: disable=invalid-name
Base = declarative_base()
SCHEMA_VERSION = 2
SCHEMA_VERSION = 3
_LOGGER = logging.getLogger(__name__)
@ -75,7 +75,9 @@ class States(Base): # type: ignore
Index('states__significant_changes',
'domain', 'last_updated', 'entity_id'),
Index('ix_states_entity_id_created',
'entity_id', 'created'),)
'entity_id', 'created'),
Index('ix_states_created_domain',
'created', 'domain'),)
@staticmethod
def from_event(event):