Skip to content

Commit 3f466f9

Browse files
committed
Enable cache_helper in more places where filename list is not actually needed
1 parent 3661c83 commit 3f466f9

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

comfy_execution/caching.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import itertools
2-
from typing import Sequence, Mapping, Dict
3-
from comfy_execution.graph import DynamicPrompt
2+
from typing import Dict, Mapping, Sequence
43

4+
import folder_paths
55
import nodes
66

7+
from comfy_execution.graph import DynamicPrompt
78
from comfy_execution.graph_utils import is_link
89

910
NODE_CLASS_CONTAINS_UNIQUE_ID: Dict[str, bool] = {}
@@ -13,7 +14,8 @@ def include_unique_id_in_input(class_type: str) -> bool:
1314
if class_type in NODE_CLASS_CONTAINS_UNIQUE_ID:
1415
return NODE_CLASS_CONTAINS_UNIQUE_ID[class_type]
1516
class_def = nodes.NODE_CLASS_MAPPINGS[class_type]
16-
NODE_CLASS_CONTAINS_UNIQUE_ID[class_type] = "UNIQUE_ID" in class_def.INPUT_TYPES().get("hidden", {}).values()
17+
with folder_paths.cache_helper: # Because we don't care about other except UNIQUE_ID
18+
NODE_CLASS_CONTAINS_UNIQUE_ID[class_type] = "UNIQUE_ID" in class_def.INPUT_TYPES().get("hidden", {}).values()
1719
return NODE_CLASS_CONTAINS_UNIQUE_ID[class_type]
1820

1921
class CacheKeySet:

comfy_execution/graph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import folder_paths
12
import nodes
23

34
from comfy_execution.graph_utils import is_link
@@ -126,7 +127,8 @@ def add_node(self, node_unique_id, include_lazy=False, subgraph_nodes=None):
126127
from_node_id, from_socket = value
127128
if subgraph_nodes is not None and from_node_id not in subgraph_nodes:
128129
continue
129-
input_type, input_category, input_info = self.get_input_info(unique_id, input_name)
130+
with folder_paths.cache_helper: # Because we don't care about other except lazy
131+
input_type, input_category, input_info = self.get_input_info(unique_id, input_name)
130132
is_lazy = input_info is not None and "lazy" in input_info and input_info["lazy"]
131133
if (include_lazy or not is_lazy) and not self.is_cached(from_node_id):
132134
node_ids.append(from_node_id)

execution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import List, Literal, NamedTuple, Optional
1111

1212
import torch
13+
import folder_paths
1314
import nodes
1415

1516
import comfy.model_management
@@ -88,7 +89,8 @@ def recursive_debug_dump(self):
8889
return result
8990

9091
def get_input_data(inputs, class_def, unique_id, outputs=None, dynprompt=None, extra_data={}):
91-
valid_inputs = class_def.INPUT_TYPES()
92+
with folder_paths.cache_helper: # Only `rawLink` has been used so far
93+
valid_inputs = class_def.INPUT_TYPES()
9294
input_data_all = {}
9395
missing_keys = {}
9496
for x in inputs:

folder_paths.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,32 @@ class CacheHelper:
6060
def __init__(self):
6161
self.cache: dict[str, tuple[list[str], dict[str, float], float]] = {}
6262
self.active = False
63+
self.refresh = False
6364

6465
def get(self, key: str, default=None) -> tuple[list[str], dict[str, float], float]:
6566
if not self.active:
6667
return default
6768
return self.cache.get(key, default)
6869

6970
def set(self, key: str, value: tuple[list[str], dict[str, float], float]) -> None:
70-
if self.active:
71-
self.cache[key] = value
71+
self.cache[key] = value
7272

7373
def clear(self):
7474
self.cache.clear()
7575

7676
def __enter__(self):
77+
if self.refresh:
78+
self.clear()
79+
self.refresh = False
7780
self.active = True
7881
return self
7982

8083
def __exit__(self, exc_type, exc_value, traceback):
8184
self.active = False
82-
self.clear()
85+
86+
def __call__(self, refresh=False):
87+
self.refresh = refresh
88+
return self
8389

8490
cache_helper = CacheHelper()
8591

server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def node_info(node_class):
584584

585585
@routes.get("/object_info")
586586
async def get_object_info(request):
587-
with folder_paths.cache_helper:
587+
with folder_paths.cache_helper(refresh=True):
588588
out = {}
589589
for x in nodes.NODE_CLASS_MAPPINGS:
590590
try:

0 commit comments

Comments
 (0)