mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Only build the recorder SupportedDialect enum once (#88402)
Every call to dialect_name was creating a new enum object in the recorder
This commit is contained in:
parent
496ab49d80
commit
3ca9f3c0d5
@ -39,6 +39,7 @@ from homeassistant.helpers.event import (
|
|||||||
from homeassistant.helpers.start import async_at_started
|
from homeassistant.helpers.start import async_at_started
|
||||||
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
from homeassistant.util.enum import try_parse_enum
|
||||||
from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS
|
from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS
|
||||||
|
|
||||||
from . import migration, statistics
|
from . import migration, statistics
|
||||||
@ -217,6 +218,7 @@ class Recorder(threading.Thread):
|
|||||||
self._commit_listener: CALLBACK_TYPE | None = None
|
self._commit_listener: CALLBACK_TYPE | None = None
|
||||||
self._periodic_listener: CALLBACK_TYPE | None = None
|
self._periodic_listener: CALLBACK_TYPE | None = None
|
||||||
self._nightly_listener: CALLBACK_TYPE | None = None
|
self._nightly_listener: CALLBACK_TYPE | None = None
|
||||||
|
self._dialect_name: SupportedDialect | None = None
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -227,9 +229,7 @@ class Recorder(threading.Thread):
|
|||||||
@property
|
@property
|
||||||
def dialect_name(self) -> SupportedDialect | None:
|
def dialect_name(self) -> SupportedDialect | None:
|
||||||
"""Return the dialect the recorder uses."""
|
"""Return the dialect the recorder uses."""
|
||||||
with contextlib.suppress(ValueError):
|
return self._dialect_name
|
||||||
return SupportedDialect(self.engine.dialect.name) if self.engine else None
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _using_file_sqlite(self) -> bool:
|
def _using_file_sqlite(self) -> bool:
|
||||||
@ -1176,7 +1176,7 @@ class Recorder(threading.Thread):
|
|||||||
validate_or_move_away_sqlite_database(self.db_url)
|
validate_or_move_away_sqlite_database(self.db_url)
|
||||||
|
|
||||||
self.engine = create_engine(self.db_url, **kwargs, future=True)
|
self.engine = create_engine(self.db_url, **kwargs, future=True)
|
||||||
|
self._dialect_name = try_parse_enum(SupportedDialect, self.engine.dialect.name)
|
||||||
sqlalchemy_event.listen(self.engine, "connect", setup_recorder_connection)
|
sqlalchemy_event.listen(self.engine, "connect", setup_recorder_connection)
|
||||||
|
|
||||||
Base.metadata.create_all(self.engine)
|
Base.metadata.create_all(self.engine)
|
||||||
|
@ -1720,7 +1720,7 @@ async def test_database_lock_without_instance(
|
|||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
|
|
||||||
instance = get_instance(hass)
|
instance = get_instance(hass)
|
||||||
with patch.object(instance, "engine", None):
|
with patch.object(instance, "engine"):
|
||||||
try:
|
try:
|
||||||
assert await instance.lock_database()
|
assert await instance.lock_database()
|
||||||
finally:
|
finally:
|
||||||
@ -1990,6 +1990,10 @@ async def test_connect_args_priority(hass: HomeAssistant, config_url) -> None:
|
|||||||
def create_connect_args(self, url):
|
def create_connect_args(self, url):
|
||||||
return ([], {"charset": "invalid"})
|
return ([], {"charset": "invalid"})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return "mysql"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dbapi(cls):
|
def dbapi(cls):
|
||||||
...
|
...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user