Skip to content

Commit

Permalink
Simplify recorder statistics_meta_manager (home-assistant#125648)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Sep 10, 2024
1 parent 40ee39f commit dd4f1a0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,11 @@ def delete_statistics_meta_duplicates(instance: Recorder, session: Session) -> N
"""Identify and delete duplicated statistics_meta.
This is used when migrating from schema version 28 to schema version 29.
Note: If this needs to be called during live schema migration it needs to
be modified to reload the statistics_meta_manager.
"""
deleted_statistics_rows = _delete_statistics_meta_duplicates(session)
if deleted_statistics_rows:
statistics_meta_manager = instance.statistics_meta_manager
statistics_meta_manager.reset()
statistics_meta_manager.load(session)
_LOGGER.info(
"Deleted %s duplicated statistics_meta rows", deleted_statistics_rows
)
1 change: 0 additions & 1 deletion homeassistant/components/recorder/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

KEEPALIVE_TIME = 30

STATISTICS_ROWS_SCHEMA_VERSION = 23
CONTEXT_ID_AS_BINARY_SCHEMA_VERSION = 36
EVENT_TYPE_IDS_SCHEMA_VERSION = 37
STATES_META_SCHEMA_VERSION = 38
Expand Down
5 changes: 1 addition & 4 deletions homeassistant/components/recorder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
MYSQLDB_URL_PREFIX,
SQLITE_MAX_BIND_VARS,
SQLITE_URL_PREFIX,
STATISTICS_ROWS_SCHEMA_VERSION,
SupportedDialect,
)
from .db_schema import (
Expand Down Expand Up @@ -797,9 +796,7 @@ def _activate_and_set_db_ready(
# since we want the frontend queries to avoid a thundering
# herd of queries to find the statistics meta data if
# there are a lot of statistics graphs on the frontend.
schema_version = self.schema_version
if schema_version >= STATISTICS_ROWS_SCHEMA_VERSION:
self.statistics_meta_manager.load(session)
self.statistics_meta_manager.load(session)

migration_changes: dict[str, int] = {
row[0]: row[1]
Expand Down

0 comments on commit dd4f1a0

Please sign in to comment.