mirror of
https://github.com/home-assistant/core.git
synced 2025-08-14 18:11:41 +02:00
avoid the empty scan most cases
This commit is contained in:
@@ -143,11 +143,17 @@ def _significant_states_stmt(
|
|||||||
# Since we are filtering on entity_id (metadata_id) we can avoid
|
# Since we are filtering on entity_id (metadata_id) we can avoid
|
||||||
# the join of the states_meta table since we already know which
|
# the join of the states_meta table since we already know which
|
||||||
# metadata_ids are in the significant domains.
|
# metadata_ids are in the significant domains.
|
||||||
|
if metadata_ids_in_significant_domains:
|
||||||
stmt = stmt.filter(
|
stmt = stmt.filter(
|
||||||
States.metadata_id.in_(metadata_ids_in_significant_domains)
|
States.metadata_id.in_(metadata_ids_in_significant_domains)
|
||||||
| (States.last_changed_ts == States.last_updated_ts)
|
| (States.last_changed_ts == States.last_updated_ts)
|
||||||
| States.last_changed_ts.is_(None)
|
| States.last_changed_ts.is_(None)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
stmt = stmt.filter(
|
||||||
|
(States.last_changed_ts == States.last_updated_ts)
|
||||||
|
| States.last_changed_ts.is_(None)
|
||||||
|
)
|
||||||
stmt = stmt.filter(States.metadata_id.in_(metadata_ids)).filter(
|
stmt = stmt.filter(States.metadata_id.in_(metadata_ids)).filter(
|
||||||
States.last_updated_ts > start_time_ts
|
States.last_updated_ts > start_time_ts
|
||||||
)
|
)
|
||||||
@@ -248,6 +254,7 @@ def get_significant_states_with_session(
|
|||||||
),
|
),
|
||||||
track_on=[
|
track_on=[
|
||||||
bool(single_metadata_id),
|
bool(single_metadata_id),
|
||||||
|
bool(metadata_ids_in_significant_domains),
|
||||||
bool(end_time_ts),
|
bool(end_time_ts),
|
||||||
significant_changes_only,
|
significant_changes_only,
|
||||||
no_attributes,
|
no_attributes,
|
||||||
|
Reference in New Issue
Block a user