mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Speed up singleton decorator so it can be used more places (#116292)
This commit is contained in:
@@ -29,7 +29,7 @@ from .core import (
|
||||
callback,
|
||||
)
|
||||
from .exceptions import DependencyError, HomeAssistantError
|
||||
from .helpers import translation
|
||||
from .helpers import singleton, translation
|
||||
from .helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from .helpers.typing import ConfigType
|
||||
from .util.async_ import create_eager_task
|
||||
@@ -671,13 +671,12 @@ class SetupPhases(StrEnum):
|
||||
"""Wait time for the packages to import."""
|
||||
|
||||
|
||||
@singleton.singleton(DATA_SETUP_STARTED)
|
||||
def _setup_started(
|
||||
hass: core.HomeAssistant,
|
||||
) -> dict[tuple[str, str | None], float]:
|
||||
"""Return the setup started dict."""
|
||||
if DATA_SETUP_STARTED not in hass.data:
|
||||
hass.data[DATA_SETUP_STARTED] = {}
|
||||
return hass.data[DATA_SETUP_STARTED] # type: ignore[no-any-return]
|
||||
return {}
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@@ -717,15 +716,12 @@ def async_pause_setup(
|
||||
)
|
||||
|
||||
|
||||
@singleton.singleton(DATA_SETUP_TIME)
|
||||
def _setup_times(
|
||||
hass: core.HomeAssistant,
|
||||
) -> defaultdict[str, defaultdict[str | None, defaultdict[SetupPhases, float]]]:
|
||||
"""Return the setup timings default dict."""
|
||||
if DATA_SETUP_TIME not in hass.data:
|
||||
hass.data[DATA_SETUP_TIME] = defaultdict(
|
||||
lambda: defaultdict(lambda: defaultdict(float))
|
||||
)
|
||||
return hass.data[DATA_SETUP_TIME] # type: ignore[no-any-return]
|
||||
return defaultdict(lambda: defaultdict(lambda: defaultdict(float)))
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
Reference in New Issue
Block a user