From ae318ee7716b320119d859b2ba3f2e4bca7c101f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Jun 2024 19:08:36 -0500 Subject: [PATCH] feat: optimize update_from_dict 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 --- src/uiprotect/data/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uiprotect/data/base.py b/src/uiprotect/data/base.py index 9a48af51..51c28db4 100644 --- a/src/uiprotect/data/base.py +++ b/src/uiprotect/data/base.py @@ -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) @@ -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)