Skip to content

Commit

Permalink
feat: optimize update_from_dict
Browse files Browse the repository at this point in the history
update_from_dict and _inject_api where always done together.

Instead of iterating all the data multiple times, iterate it
once and inject the api as we go
  • Loading branch information
bdraco committed Jun 17, 2024
1 parent 29c931e commit ae318ee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/uiprotect/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ def update_from_dict(cls: ProtectObject, data: dict[str, Any]) -> ProtectObject:
value: Any

for key, item in data.items():
if key == "api":
continue
if has_unifi_objs and key in unifi_objs and isinstance(item, dict):
item["api"] = api
unifi_obj = getattr(cls, key)
Expand All @@ -528,6 +526,8 @@ def update_from_dict(cls: ProtectObject, data: dict[str, Any]) -> ProtectObject:
for i in item.values():
if isinstance(i, dict):
i["api"] = api
elif key == "api":
continue
value = convert_unifi_data(item, _fields[key])

setattr(cls, key, value)
Expand Down

0 comments on commit ae318ee

Please sign in to comment.