Skip to content

Commit 897debb

Browse files
committed
improved: prevent hang UI while CNR loading
fixed: normalize id for pyproject.toml
1 parent 0b43716 commit 897debb

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed

cm-cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def set_channel_mode(self, channel, mode):
118118
if channel is not None:
119119
self.channel = channel
120120

121-
asyncio.run(unified_manager.reload(cache_mode=self.mode == 'cache'))
121+
asyncio.run(unified_manager.reload(cache_mode=self.mode == 'cache', dont_wait=False))
122122
asyncio.run(unified_manager.load_nightly(self.channel, self.mode))
123123

124124
def set_no_deps(self, no_deps):

glob/cnr_utils.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,49 @@
44
import manager_util
55
import toml
66
import os
7+
import asyncio
78

89
base_url = "https://api.comfy.org"
910

1011

11-
async def get_cnr_data(page=1, limit=1000, cache_mode=True):
12-
try:
13-
uri = f'{base_url}/nodes?page={page}&limit={limit}'
14-
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode)
12+
lock = asyncio.Lock()
13+
14+
is_cache_loading = False
1515

16+
async def get_cnr_data(page=1, limit=1000, cache_mode=True, dont_wait=True):
17+
global is_cache_loading
18+
19+
uri = f'{base_url}/nodes?page={page}&limit={limit}'
20+
21+
def touch(json_obj):
1622
for v in json_obj['nodes']:
1723
if 'latest_version' not in v:
1824
v['latest_version'] = dict(version='nightly')
1925

26+
27+
if cache_mode:
28+
if dont_wait:
29+
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode, dont_wait=True) # fallback
30+
31+
if 'nodes' in json_obj:
32+
touch(json_obj)
33+
return json_obj['nodes']
34+
else:
35+
return {}
36+
37+
is_cache_loading = True
38+
39+
try:
40+
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode)
41+
touch(json_obj)
42+
2043
return json_obj['nodes']
2144
except:
2245
res = {}
2346
print("Cannot connect to comfyregistry.")
47+
finally:
48+
if cache_mode:
49+
is_cache_loading = False
2450

2551
return res
2652

@@ -92,7 +118,7 @@ def install_node(node_id, version=None):
92118

93119

94120
def all_versions_of_node(node_id):
95-
url = f"https://api.comfy.org/nodes/{node_id}/versions?statuses=NodeVersionStatusActive&statuses=NodeVersionStatusPending"
121+
url = f"{base_url}/nodes/{node_id}/versions?statuses=NodeVersionStatusActive&statuses=NodeVersionStatusPending"
96122

97123
response = requests.get(url)
98124
if response.status_code == 200:
@@ -113,7 +139,7 @@ def read_cnr_info(fullpath):
113139
data = toml.load(f)
114140

115141
project = data.get('project', {})
116-
name = project.get('name')
142+
name = project.get('name').strip().lower()
117143
version = project.get('version')
118144

119145
urls = project.get('urls', {})

glob/manager_core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from node_package import InstalledNodePackage
4242

4343

44-
version_code = [3, 6, 5]
44+
version_code = [3, 7]
4545
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
4646

4747

@@ -507,7 +507,7 @@ def update_cache_at_path(self, fullpath):
507507
if node_package.is_disabled and node_package.is_nightly:
508508
self.nightly_inactive_nodes[node_package.id] = node_package.fullpath
509509

510-
if node_package.is_enabled:
510+
if node_package.is_enabled and not node_package.is_unknown:
511511
self.active_nodes[node_package.id] = node_package.version, node_package.fullpath
512512

513513
if node_package.is_enabled and node_package.is_unknown:
@@ -664,7 +664,7 @@ def get_from_cnr_inactive_nodes(self, node_id, ver=None):
664664

665665
return latest
666666

667-
async def reload(self, cache_mode):
667+
async def reload(self, cache_mode, dont_wait=True):
668668
self.custom_node_map_cache = {}
669669
self.cnr_inactive_nodes = {} # node_id -> node_version -> fullpath
670670
self.nightly_inactive_nodes = {} # node_id -> fullpath
@@ -673,7 +673,7 @@ async def reload(self, cache_mode):
673673
self.active_nodes = {} # node_id -> node_version * fullpath
674674

675675
# reload 'cnr_map' and 'repo_cnr_map'
676-
cnrs = await cnr_utils.get_cnr_data(cache_mode=cache_mode)
676+
cnrs = await cnr_utils.get_cnr_data(cache_mode=cache_mode, dont_wait=dont_wait)
677677

678678
for x in cnrs:
679679
self.cnr_map[x['id']] = x

glob/manager_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ async def get_cache(filename):
14151415
await asyncio.gather(a, b, c, d, e)
14161416

14171417
# load at least once
1418-
await core.unified_manager.reload('cache')
1418+
await core.unified_manager.reload('cache', dont_wait=False)
14191419
await core.unified_manager.get_custom_nodes('default', 'cache')
14201420

14211421
# NOTE: hide migration button temporarily.

glob/manager_util.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import subprocess
1212
import sys
1313
import re
14+
import logging
15+
1416

1517
cache_lock = threading.Lock()
1618

@@ -128,15 +130,26 @@ async def get_data(uri, silent=False):
128130
return json_obj
129131

130132

131-
async def get_data_with_cache(uri, silent=False, cache_mode=True):
133+
async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False):
132134
cache_uri = str(simple_hash(uri)) + '_' + os.path.basename(uri).replace('&', "_").replace('?', "_").replace('=', "_")
133135
cache_uri = os.path.join(cache_dir, cache_uri+'.json')
134136

137+
if cache_mode and dont_wait:
138+
# NOTE: return the cache if possible, even if it is expired, so do not cache
139+
if not os.path.exists(cache_uri):
140+
logging.error(f"[ComfyUI-Manager] The network connection is unstable, so it is operating in fallback mode: {uri}")
141+
142+
return {}
143+
else:
144+
if not is_file_created_within_one_day(cache_uri):
145+
logging.error(f"[ComfyUI-Manager] The network connection is unstable, so it is operating in outdated cache mode: {uri}")
146+
147+
return await get_data(cache_uri, silent=silent)
148+
135149
if cache_mode and is_file_created_within_one_day(cache_uri):
136150
json_obj = await get_data(cache_uri, silent=silent)
137151
else:
138152
json_obj = await get_data(uri, silent=silent)
139-
140153
with cache_lock:
141154
with open(cache_uri, "w", encoding='utf-8') as file:
142155
json.dump(json_obj, file, indent=4, sort_keys=True)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-manager"
33
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
4-
version = "3.6.5"
4+
version = "3.7"
55
license = { file = "LICENSE.txt" }
66
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
77

0 commit comments

Comments
 (0)