Speed up registry config websocket api calls with list comps (#110693)
* Speed up registry config websocket api calls with list comps list comps are faster than generator expressions, even more so in python 3.12 since https://peps.python.org/pep-0709/ https://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehensions/62709748#62709748 * more readable
This commit is contained in:
parent
59d7bceaee
commit
1608e05be6
2 changed files with 12 additions and 15 deletions
|
@ -47,15 +47,14 @@ def websocket_list_devices(
|
|||
f'"success":true,"result": ['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
msg_json = (
|
||||
msg_json_prefix
|
||||
+ b",".join(
|
||||
inner = b",".join(
|
||||
[
|
||||
entry.json_repr
|
||||
for entry in registry.devices.values()
|
||||
if entry.json_repr is not None
|
||||
)
|
||||
+ b"]}"
|
||||
]
|
||||
)
|
||||
msg_json = b"".join((msg_json_prefix, inner, b"]}"))
|
||||
connection.send_message(msg_json)
|
||||
|
||||
|
||||
|
|
|
@ -45,15 +45,14 @@ def websocket_list_entities(
|
|||
'"success":true,"result": ['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
msg_json = (
|
||||
msg_json_prefix
|
||||
+ b",".join(
|
||||
inner = b",".join(
|
||||
[
|
||||
entry.partial_json_repr
|
||||
for entry in registry.entities.values()
|
||||
if entry.partial_json_repr is not None
|
||||
)
|
||||
+ b"]}"
|
||||
]
|
||||
)
|
||||
msg_json = b"".join((msg_json_prefix, inner, b"]}"))
|
||||
connection.send_message(msg_json)
|
||||
|
||||
|
||||
|
@ -77,15 +76,14 @@ def websocket_list_entities_for_display(
|
|||
f'"result":{{"entity_categories":{_ENTITY_CATEGORIES_JSON},"entities":['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
msg_json = (
|
||||
msg_json_prefix
|
||||
+ b",".join(
|
||||
inner = b",".join(
|
||||
[
|
||||
entry.display_json_repr
|
||||
for entry in registry.entities.values()
|
||||
if entry.disabled_by is None and entry.display_json_repr is not None
|
||||
)
|
||||
+ b"]}}"
|
||||
]
|
||||
)
|
||||
msg_json = b"".join((msg_json_prefix, inner, b"]}}"))
|
||||
connection.send_message(msg_json)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue