forked from nkchocoai/ComfyUI-SaveImageWithMetaData
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
69 lines (49 loc) · 2.17 KB
/
__init__.py
File metadata and controls
69 lines (49 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import functools
from .hook import pre_execute, pre_get_input_data
import execution
# refer. https://stackoverflow.com/a/35758398
def prefix_function(function, prefunction):
@functools.wraps(function)
def run(*args, **kwargs):
prefunction(*args, **kwargs)
return function(*args, **kwargs)
return run
execution.PromptExecutor.execute = prefix_function(
execution.PromptExecutor.execute, pre_execute
)
execution.get_input_data = prefix_function(execution.get_input_data, pre_get_input_data)
def get_output_cache_wrapper(self, input_unique_id, unique_id):
return self.output_cache.get(input_unique_id)
from comfy_execution.graph import ExecutionList
ExecutionList.get_output_cache = get_output_cache_wrapper
# --- Compatibility shims for ComfyUI cache objects ---
# Make HierarchicalCache/LRUCache/NullCache expose get_output_cache(...) expected by execution.get_input_data(...)
from comfy_execution.caching import HierarchicalCache, LRUCache, NullCache
def _cache_get_output_cache(self, input_unique_id, unique_id):
# unique_id is ignored here; we only need cached outputs of input_unique_id
try:
return self.get(input_unique_id)
except Exception:
return None
def _nullcache_get_output_cache(self, input_unique_id, unique_id):
return None
if not hasattr(HierarchicalCache, "get_output_cache"):
HierarchicalCache.get_output_cache = _cache_get_output_cache
if not hasattr(LRUCache, "get_output_cache"):
LRUCache.get_output_cache = _cache_get_output_cache
if not hasattr(NullCache, "get_output_cache"):
NullCache.get_output_cache = _nullcache_get_output_cache
def _cache_get_cache(self, input_unique_id, unique_id):
# unique_id is ignored here; we only need cached outputs of input_unique_id
try:
return self.get(input_unique_id)
except Exception:
return None
def _nullcache_get_cache(self, input_unique_id, unique_id):
return None
if not hasattr(HierarchicalCache, "get_cache"):
HierarchicalCache.get_cache = _cache_get_cache
if not hasattr(LRUCache, "get_cache"):
LRUCache.get_cache = _cache_get_cache
if not hasattr(NullCache, "get_cache"):
NullCache.get_cache = _nullcache_get_cache