mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Reduce overhead to call get_mqtt_data (#117887)
We call this 100000s of times if there are many subscriptions https://github.com/home-assistant/core/pull/109030#issuecomment-2123612530
This commit is contained in:
parent
f429bfa903
commit
4ed45a322c
@ -241,6 +241,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
websocket_api.async_register_command(hass, websocket_subscribe)
|
websocket_api.async_register_command(hass, websocket_subscribe)
|
||||||
websocket_api.async_register_command(hass, websocket_mqtt_info)
|
websocket_api.async_register_command(hass, websocket_mqtt_info)
|
||||||
hass.data[DATA_MQTT] = mqtt_data = MqttData(config=mqtt_yaml, client=client)
|
hass.data[DATA_MQTT] = mqtt_data = MqttData(config=mqtt_yaml, client=client)
|
||||||
|
get_mqtt_data.cache_clear()
|
||||||
client.start(mqtt_data)
|
client.start(mqtt_data)
|
||||||
|
|
||||||
# Restore saved subscriptions
|
# Restore saved subscriptions
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from functools import lru_cache
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -216,6 +217,7 @@ def valid_birth_will(config: ConfigType) -> ConfigType:
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
def get_mqtt_data(hass: HomeAssistant) -> MqttData:
|
def get_mqtt_data(hass: HomeAssistant) -> MqttData:
|
||||||
"""Return typed MqttData from hass.data[DATA_MQTT]."""
|
"""Return typed MqttData from hass.data[DATA_MQTT]."""
|
||||||
mqtt_data: MqttData = hass.data[DATA_MQTT]
|
mqtt_data: MqttData = hass.data[DATA_MQTT]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user