Skip to content

Commit c6153ea

Browse files
committed
* FIXED: Resolved an issue where cache updates were not working properly.
* IMPROVED: Instead of updating the entire CNR cache at once, the process now divides it into 30-page queries. * IMPROVED: Clicking on the titles of nodes that exist only in CNR now opens the GitHub repository link instead of the CNR link, where possible. * ADDED: Added information about `extra_model_paths.yaml` to the README.md file. Comfy-Org#1457
1 parent 191bffe commit c6153ea

File tree

8 files changed

+88
-29
lines changed

8 files changed

+88
-29
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ In `ComfyUI-Manager` V3.0 and later, configuration files and dynamically generat
146146
* Saved snapshot files: `<USER_DIRECTORY>/default/ComfyUI-Manager/snapshots`
147147
* Startup script files: `<USER_DIRECTORY>/default/ComfyUI-Manager/startup-scripts`
148148
* Component files: `<USER_DIRECTORY>/default/ComfyUI-Manager/components`
149-
149+
150+
151+
## `extra_model_paths.yaml` Configuration
152+
The following settings are applied based on the section marked as `is_default`.
153+
154+
* `custom_nodes`: Path for installing custom nodes
155+
* Importing does not need to adhere to the path set as `is_default`, but this is the path where custom nodes are installed by the `ComfyUI Nodes Manager`.
156+
* `download_model_base`: Path for downloading models
157+
150158

151159
## Snapshot-Manager
152160
* When you press `Save snapshot` or use `Update All` on `Manager Menu`, the current installation status snapshot is saved.

extras.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"comfyui-layerdiffuse",
1010
"comfyui-liveportraitkj",
1111
"aigodlike-comfyui-translation",
12-
"comfyui-reactor-node",
12+
"comfyui-reactor",
1313
"comfyui_instantid",
1414
"sd-dynamic-thresholding",
1515
"pr-was-node-suite-comfyui-47064894",

glob/cnr_utils.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import toml
66
import os
77
import asyncio
8+
import json
89

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

@@ -13,33 +14,55 @@
1314

1415
is_cache_loading = False
1516

16-
async def get_cnr_data(page=1, limit=1000, cache_mode=True, dont_wait=True):
17+
async def get_cnr_data(cache_mode=True, dont_wait=True):
1718
global is_cache_loading
1819

19-
uri = f'{base_url}/nodes?page={page}&limit={limit}'
20+
uri = f'{base_url}/nodes'
2021

21-
def touch(json_obj):
22-
for v in json_obj['nodes']:
22+
async def fetch_all():
23+
remained = True
24+
page = 1
25+
26+
full_nodes = {}
27+
while remained:
28+
sub_uri = f'{base_url}/nodes?page={page}&limit=30'
29+
sub_json_obj = await manager_util.get_data_with_cache(sub_uri, cache_mode=False, silent=True)
30+
remained = page < sub_json_obj['totalPages']
31+
32+
for x in sub_json_obj['nodes']:
33+
full_nodes[x['id']] = x
34+
35+
if page % 5 == 0:
36+
print(f"FETCH ComfyRegistry Data: {page}/{sub_json_obj['totalPages']}")
37+
page += 1
38+
39+
print("FETCH ComfyRegistry Data [DONE]")
40+
41+
for v in full_nodes.values():
2342
if 'latest_version' not in v:
2443
v['latest_version'] = dict(version='nightly')
2544

45+
return {'nodes': list(full_nodes.values())}
2646

2747
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
48+
is_cache_loading = True
49+
cache_state = manager_util.get_cache_state(uri)
3050

31-
if 'nodes' in json_obj:
32-
touch(json_obj)
33-
return json_obj['nodes']
34-
else:
51+
if dont_wait:
52+
if cache_state == 'not-cached':
3553
return {}
54+
else:
55+
print("[ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.")
56+
with open(manager_util.get_cache_path(uri), 'r', encoding="UTF-8", errors="ignore") as json_file:
57+
return json.load(json_file)['nodes']
3658

37-
is_cache_loading = True
59+
if cache_state == 'cached':
60+
with open(manager_util.get_cache_path(uri), 'r', encoding="UTF-8", errors="ignore") as json_file:
61+
return json.load(json_file)['nodes']
3862

3963
try:
40-
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode)
41-
touch(json_obj)
42-
64+
json_obj = await fetch_all()
65+
manager_util.save_to_cache(uri, json_obj)
4366
return json_obj['nodes']
4467
except:
4568
res = {}

glob/manager_core.py

Lines changed: 6 additions & 6 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, 8, 1]
44+
version_code = [3, 9]
4545
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
4646

4747

@@ -682,11 +682,10 @@ async def reload(self, cache_mode, dont_wait=True):
682682
self.active_nodes = {} # node_id -> node_version * fullpath
683683

684684
# reload 'cnr_map' and 'repo_cnr_map'
685-
cnrs = await cnr_utils.get_cnr_data(cache_mode=cache_mode, dont_wait=dont_wait)
685+
cnrs = await cnr_utils.get_cnr_data(cache_mode=cache_mode=='cache', dont_wait=dont_wait)
686686

687687
for x in cnrs:
688688
self.cnr_map[x['id']] = x
689-
690689
if 'repository' in x:
691690
normalized_url = git_utils.normalize_url(x['repository'])
692691
self.repo_cnr_map[normalized_url] = x
@@ -2696,8 +2695,8 @@ def map_to_unified_keys(json_obj):
26962695
return res
26972696

26982697

2699-
async def get_unified_total_nodes(channel, mode):
2700-
await unified_manager.reload(mode)
2698+
async def get_unified_total_nodes(channel, mode, regsitry_cache_mode='cache'):
2699+
await unified_manager.reload(regsitry_cache_mode)
27012700

27022701
res = await unified_manager.get_custom_nodes(channel, mode)
27032702

@@ -2780,6 +2779,7 @@ async def get_unified_total_nodes(channel, mode):
27802779
author = cnr['publisher']['name']
27812780
title = cnr['name']
27822781
reference = f"https://registry.comfy.org/nodes/{cnr['id']}"
2782+
repository = cnr.get('repository', '')
27832783
install_type = "cnr"
27842784
description = cnr.get('description', '')
27852785

@@ -2811,7 +2811,7 @@ async def get_unified_total_nodes(channel, mode):
28112811
if ver is None:
28122812
ver = cnr['latest_version']['version']
28132813

2814-
item = dict(author=author, title=title, reference=reference, install_type=install_type,
2814+
item = dict(author=author, title=title, reference=reference, repository=repository, install_type=install_type,
28152815
description=description, state=state, updatable=updatable, version=ver)
28162816

28172817
if active_version:

glob/manager_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ async def fetch_customnode_list(request):
566566
else:
567567
channel = core.get_config()['channel_url']
568568

569-
node_packs = await core.get_unified_total_nodes(channel, request.rel_url.query["mode"])
569+
node_packs = await core.get_unified_total_nodes(channel, request.rel_url.query["mode"], 'cache')
570570
json_obj_github = core.get_data_by_mode(request.rel_url.query["mode"], 'github-stats.json', 'default')
571571
json_obj_extras = core.get_data_by_mode(request.rel_url.query["mode"], 'extras.json', 'default')
572572

@@ -1434,8 +1434,8 @@ async def get_cache(filename):
14341434
await asyncio.gather(a, b, c, d, e)
14351435

14361436
# load at least once
1437-
await core.unified_manager.reload('cache', dont_wait=False)
1438-
await core.unified_manager.get_custom_nodes('default', 'cache')
1437+
await core.unified_manager.reload('remote', dont_wait=False)
1438+
await core.unified_manager.get_custom_nodes('default', 'remote')
14391439

14401440
# NOTE: hide migration button temporarily.
14411441
# if not core.get_config()['skip_migration_check']:

glob/manager_util.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,34 @@ async def get_data(uri, silent=False):
130130
return json_obj
131131

132132

133-
async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False):
133+
def get_cache_path(uri):
134134
cache_uri = str(simple_hash(uri)) + '_' + os.path.basename(uri).replace('&', "_").replace('?', "_").replace('=', "_")
135-
cache_uri = os.path.join(cache_dir, cache_uri+'.json')
135+
return os.path.join(cache_dir, cache_uri+'.json')
136+
137+
138+
def get_cache_state(uri):
139+
cache_uri = get_cache_path(uri)
140+
141+
if not os.path.exists(cache_uri):
142+
return "not-cached"
143+
elif is_file_created_within_one_day(cache_uri):
144+
return "cached"
145+
146+
return "expired"
147+
148+
149+
def save_to_cache(uri, json_obj, silent=False):
150+
cache_uri = get_cache_path(uri)
151+
152+
with cache_lock:
153+
with open(cache_uri, "w", encoding='utf-8') as file:
154+
json.dump(json_obj, file, indent=4, sort_keys=True)
155+
if not silent:
156+
logging.info(f"[ComfyUI-Manager] default cache updated: {uri}")
157+
158+
159+
async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False):
160+
cache_uri = get_cache_path(uri)
136161

137162
if cache_mode and dont_wait:
138163
# NOTE: return the cache if possible, even if it is expired, so do not cache

js/custom-nodes-manager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,10 @@ export class CustomNodesManager {
975975
}
976976

977977
const link = document.createElement('a');
978-
link.href = rowItem.reference;
978+
if(rowItem.originalData.repository)
979+
link.href = rowItem.originalData.repository;
980+
else
981+
link.href = rowItem.reference;
979982
link.target = '_blank';
980983
link.innerHTML = `<b>${title}</b>`;
981984
container.appendChild(link);

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.8.1"
4+
version = "3.9"
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)