Deduplicate event_types in the events table (#89465)

* Deduplicate event_types in the events table

* Deduplicate event_types in the events table

* more fixes

* adjust

* adjust

* fix product

* fix tests

* adjust

* migrate

* migrate

* migrate

* more test fixes

* more test fixes

* fix

* migration test

* adjust

* speed up

* fix index

* fix more tests

* handle db failure

* preload

* tweak

* adjust

* fix stale docs strings, remove dead code

* refactor

* fix slow tests

* coverage

* self join to resolve query performance

* fix typo

* no need for quiet

* no need to drop index already dropped

* remove index that will never be used

* drop index sooner as we no longer use it

* Revert "remove index that will never be used"

This reverts commit 461aad2c52.

* typo
This commit is contained in:
J. Nick Koston 2023-03-11 09:54:55 -10:00 committed by GitHub
parent 56454c8580
commit 8bd43760b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 725 additions and 39 deletions

View file

@ -15,6 +15,7 @@ from homeassistant.components.recorder.db_schema import (
OLD_ENTITY_ID_IN_EVENT,
EventData,
Events,
EventTypes,
States,
)
@ -78,7 +79,9 @@ def _apply_entities_context_union(
select_events_context_only()
.select_from(entities_cte)
.outerjoin(Events, entities_cte.c.context_id_bin == Events.context_id_bin)
).outerjoin(EventData, (Events.data_id == EventData.data_id)),
.outerjoin(EventTypes, (Events.event_type_id == EventTypes.event_type_id))
.outerjoin(EventData, (Events.data_id == EventData.data_id))
),
apply_states_context_hints(
select_states_context_only()
.select_from(entities_cte)