Skip to content

Commit

Permalink
Minor refactor of IsChangedCache.get
Browse files Browse the repository at this point in the history
  • Loading branch information
guill committed Apr 22, 2024
1 parent b3e547f commit fa48ad3
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fa48ad3

Please sign in to comment.