Simplify recorder statistics_meta_manager (#125648)

This commit is contained in:
Erik Montnemery 2024-09-10 21:00:06 +02:00 committed by GitHub
parent 40ee39f258
commit dd4f1a0d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 8 deletions

View File

@ -247,12 +247,11 @@ def delete_statistics_meta_duplicates(instance: Recorder, session: Session) -> N
"""Identify and delete duplicated statistics_meta. """Identify and delete duplicated statistics_meta.
This is used when migrating from schema version 28 to schema version 29. 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) deleted_statistics_rows = _delete_statistics_meta_duplicates(session)
if deleted_statistics_rows: if deleted_statistics_rows:
statistics_meta_manager = instance.statistics_meta_manager
statistics_meta_manager.reset()
statistics_meta_manager.load(session)
_LOGGER.info( _LOGGER.info(
"Deleted %s duplicated statistics_meta rows", deleted_statistics_rows "Deleted %s duplicated statistics_meta rows", deleted_statistics_rows
) )

View File

@ -54,7 +54,6 @@ ATTR_APPLY_FILTER = "apply_filter"
KEEPALIVE_TIME = 30 KEEPALIVE_TIME = 30
STATISTICS_ROWS_SCHEMA_VERSION = 23
CONTEXT_ID_AS_BINARY_SCHEMA_VERSION = 36 CONTEXT_ID_AS_BINARY_SCHEMA_VERSION = 36
EVENT_TYPE_IDS_SCHEMA_VERSION = 37 EVENT_TYPE_IDS_SCHEMA_VERSION = 37
STATES_META_SCHEMA_VERSION = 38 STATES_META_SCHEMA_VERSION = 38

View File

@ -63,7 +63,6 @@ from .const import (
MYSQLDB_URL_PREFIX, MYSQLDB_URL_PREFIX,
SQLITE_MAX_BIND_VARS, SQLITE_MAX_BIND_VARS,
SQLITE_URL_PREFIX, SQLITE_URL_PREFIX,
STATISTICS_ROWS_SCHEMA_VERSION,
SupportedDialect, SupportedDialect,
) )
from .db_schema import ( from .db_schema import (
@ -797,8 +796,6 @@ class Recorder(threading.Thread):
# since we want the frontend queries to avoid a thundering # since we want the frontend queries to avoid a thundering
# herd of queries to find the statistics meta data if # herd of queries to find the statistics meta data if
# there are a lot of statistics graphs on the frontend. # 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] = { migration_changes: dict[str, int] = {