mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Simplify recorder statistics_meta_manager (#125648)
This commit is contained in:
parent
40ee39f258
commit
dd4f1a0d0f
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
|
@ -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,9 +796,7 @@ 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
|
self.statistics_meta_manager.load(session)
|
||||||
if schema_version >= STATISTICS_ROWS_SCHEMA_VERSION:
|
|
||||||
self.statistics_meta_manager.load(session)
|
|
||||||
|
|
||||||
migration_changes: dict[str, int] = {
|
migration_changes: dict[str, int] = {
|
||||||
row[0]: row[1]
|
row[0]: row[1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user