⚡️ Speed up function clean_element_before_hashing by 827% (#1890)
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -160,16 +160,17 @@ def json_to_html(element: dict, need_skyvern_attrs: bool = True) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def clean_element_before_hashing(element: dict) -> dict:
|
def clean_element_before_hashing(element: dict) -> dict:
|
||||||
element_copy = copy.deepcopy(element)
|
def clean_nested(element: dict) -> dict:
|
||||||
element_copy.pop("id", None)
|
element_cleaned = {key: value for key, value in element.items() if key not in {"id", "rect", "frame_index"}}
|
||||||
element_copy.pop("rect", None)
|
if "attributes" in element:
|
||||||
element_copy.pop("frame_index", None)
|
attributes_cleaned = {key: value for key, value in element["attributes"].items() if key != SKYVERN_ID_ATTR}
|
||||||
if "attributes" in element_copy:
|
element_cleaned["attributes"] = attributes_cleaned
|
||||||
element_copy["attributes"].pop(SKYVERN_ID_ATTR, None)
|
if "children" in element:
|
||||||
if "children" in element_copy:
|
children_cleaned = [clean_nested(child) for child in element["children"]]
|
||||||
for idx, child in enumerate(element_copy["children"]):
|
element_cleaned["children"] = children_cleaned
|
||||||
element_copy["children"][idx] = clean_element_before_hashing(child)
|
return element_cleaned
|
||||||
return element_copy
|
|
||||||
|
return clean_nested(element)
|
||||||
|
|
||||||
|
|
||||||
def hash_element(element: dict) -> str:
|
def hash_element(element: dict) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user