mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Cache serialize of manifest for loaded integrations (#117965)
* Cache serialize of manifest for loaded integrations The manifest/list and manifest/get websocket apis are called frequently when moving around in the UI. Since the manifest does not change we can make the the serialized version a cached property * reduce * reduce
This commit is contained in:
@ -46,10 +46,10 @@ from homeassistant.helpers.json import (
|
||||
ExtendedJSONEncoder,
|
||||
find_paths_unserializable_data,
|
||||
json_bytes,
|
||||
json_fragment,
|
||||
)
|
||||
from homeassistant.helpers.service import async_get_all_descriptions
|
||||
from homeassistant.loader import (
|
||||
Integration,
|
||||
IntegrationNotFound,
|
||||
async_get_integration,
|
||||
async_get_integration_descriptions,
|
||||
@ -505,19 +505,15 @@ async def handle_manifest_list(
|
||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Handle integrations command."""
|
||||
wanted_integrations = msg.get("integrations")
|
||||
if wanted_integrations is None:
|
||||
wanted_integrations = async_get_loaded_integrations(hass)
|
||||
|
||||
ints_or_excs = await async_get_integrations(hass, wanted_integrations)
|
||||
integrations: list[Integration] = []
|
||||
ints_or_excs = await async_get_integrations(
|
||||
hass, msg.get("integrations") or async_get_loaded_integrations(hass)
|
||||
)
|
||||
manifest_json_fragments: list[json_fragment] = []
|
||||
for int_or_exc in ints_or_excs.values():
|
||||
if isinstance(int_or_exc, Exception):
|
||||
raise int_or_exc
|
||||
integrations.append(int_or_exc)
|
||||
connection.send_result(
|
||||
msg["id"], [integration.manifest for integration in integrations]
|
||||
)
|
||||
manifest_json_fragments.append(int_or_exc.manifest_json_fragment)
|
||||
connection.send_result(msg["id"], manifest_json_fragments)
|
||||
|
||||
|
||||
@decorators.websocket_command(
|
||||
@ -530,9 +526,10 @@ async def handle_manifest_get(
|
||||
"""Handle integrations command."""
|
||||
try:
|
||||
integration = await async_get_integration(hass, msg["integration"])
|
||||
connection.send_result(msg["id"], integration.manifest)
|
||||
except IntegrationNotFound:
|
||||
connection.send_error(msg["id"], const.ERR_NOT_FOUND, "Integration not found")
|
||||
else:
|
||||
connection.send_result(msg["id"], integration.manifest_json_fragment)
|
||||
|
||||
|
||||
@callback
|
||||
|
Reference in New Issue
Block a user