From f27d73fc3461f8d3fb36a829504ed5ec6d0d253a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 19 Mar 2023 16:05:07 -1000 Subject: [PATCH] Remove legacy event lookups from logbook (#89945) Events recorded with Home Assistant 2022.5.x or older will no longer display context information in the logbook --- .../components/logbook/queries/all.py | 16 +---------- .../components/logbook/queries/common.py | 28 ------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/homeassistant/components/logbook/queries/all.py b/homeassistant/components/logbook/queries/all.py index 5311d5a9d6e..8c37bf22da9 100644 --- a/homeassistant/components/logbook/queries/all.py +++ b/homeassistant/components/logbook/queries/all.py @@ -12,12 +12,7 @@ from homeassistant.components.recorder.db_schema import ( States, ) -from .common import ( - apply_states_filters, - legacy_select_events_context_id, - select_events_without_states, - select_states, -) +from .common import apply_states_filters, select_events_without_states, select_states def all_stmt( @@ -33,9 +28,6 @@ def all_stmt( lambda: select_events_without_states(start_day, end_day, event_types) ) if context_id_bin is not None: - # Once all the old `state_changed` events - # are gone from the database remove the - # _legacy_select_events_context_id() stmt += lambda s: s.where(Events.context_id_bin == context_id_bin).union_all( _states_query_for_context_id( start_day, @@ -43,12 +35,6 @@ def all_stmt( # https://github.com/python/mypy/issues/2608 context_id_bin, # type:ignore[arg-type] ), - legacy_select_events_context_id( - start_day, - end_day, - # https://github.com/python/mypy/issues/2608 - context_id_bin, # type:ignore[arg-type] - ), ) else: if events_entity_filter is not None: diff --git a/homeassistant/components/logbook/queries/common.py b/homeassistant/components/logbook/queries/common.py index c63bb30eb6c..08bf1b8ab9b 100644 --- a/homeassistant/components/logbook/queries/common.py +++ b/homeassistant/components/logbook/queries/common.py @@ -166,34 +166,6 @@ def select_states() -> Select: ) -def legacy_select_events_context_id( - start_day: float, end_day: float, context_id_bin: bytes -) -> Select: - """Generate a legacy events context id select that also joins states.""" - # This can be removed once we no longer have event_ids in the states table - return ( - select( - *EVENT_COLUMNS, - literal(value=None, type_=sqlalchemy.String).label("shared_data"), - *STATE_COLUMNS, - NOT_CONTEXT_ONLY, - ) - .outerjoin(States, (Events.event_id == States.event_id)) - .where( - (States.last_updated_ts == States.last_changed_ts) - | States.last_changed_ts.is_(None) - ) - .where(_not_continuous_entity_matcher()) - .outerjoin( - StateAttributes, (States.attributes_id == StateAttributes.attributes_id) - ) - .outerjoin(StatesMeta, (States.metadata_id == StatesMeta.metadata_id)) - .outerjoin(EventTypes, (Events.event_type_id == EventTypes.event_type_id)) - .where((Events.time_fired_ts > start_day) & (Events.time_fired_ts < end_day)) - .where(Events.context_id_bin == context_id_bin) - ) - - def apply_states_filters(sel: Select, start_day: float, end_day: float) -> Select: """Filter states by time range.