From fa48ad3a1fcb45b0027eae58fdab073cb9f269ef Mon Sep 17 00:00:00 2001 From: Jacob Segal Date: Sun, 21 Apr 2024 21:39:52 -0700 Subject: [PATCH] Minor refactor of IsChangedCache.get --- execution.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/execution.py b/execution.py index 4abc10d9e47..1e35da8db1a 100644 --- a/execution.py +++ b/execution.py @@ -33,24 +33,28 @@ def __init__(self, dynprompt, outputs_cache): self.is_changed = {} def get(self, node_id): - if node_id not in self.is_changed: - node = self.dynprompt.get_node(node_id) - class_type = node["class_type"] - class_def = nodes.NODE_CLASS_MAPPINGS[class_type] - if hasattr(class_def, "IS_CHANGED"): - if "is_changed" in node: - self.is_changed[node_id] = node["is_changed"] - else: - input_data_all, _ = get_input_data(node["inputs"], class_def, node_id, self.outputs_cache) - try: - is_changed = map_node_over_list(class_def, input_data_all, "IS_CHANGED") - node["is_changed"] = [None if isinstance(x, ExecutionBlocker) else x for x in is_changed] - self.is_changed[node_id] = node["is_changed"] - except: - node["is_changed"] = float("NaN") - self.is_changed[node_id] = node["is_changed"] - else: - self.is_changed[node_id] = False + if node_id in self.is_changed: + return self.is_changed[node_id] + + node = self.dynprompt.get_node(node_id) + class_type = node["class_type"] + class_def = nodes.NODE_CLASS_MAPPINGS[class_type] + if not hasattr(class_def, "IS_CHANGED"): + self.is_changed[node_id] = False + return self.is_changed[node_id] + + if "is_changed" in node: + self.is_changed[node_id] = node["is_changed"] + return self.is_changed[node_id] + + input_data_all, _ = get_input_data(node["inputs"], class_def, node_id, self.outputs_cache) + try: + is_changed = map_node_over_list(class_def, input_data_all, "IS_CHANGED") + node["is_changed"] = [None if isinstance(x, ExecutionBlocker) else x for x in is_changed] + except: + node["is_changed"] = float("NaN") + finally: + self.is_changed[node_id] = node["is_changed"] return self.is_changed[node_id] class CacheSet: