Skip to content

Commit fa20899

Browse files
committed
optimize: better badge
optimize: cache data mode improve: robust data retrieve update DB
1 parent 6151461 commit fa20899

11 files changed

+244
-185
lines changed

.cache/.cache_directory

Whitespace-only changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ __pycache__/
22
.idea/
33
.vscode/
44
.tmp
5+
.cache
56
config.ini
67
snapshots/**
78
startup-scripts/**

__init__.py

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import signal
1919
import nodes
2020

21-
version = "V1.9"
21+
version = "V1.10"
2222
print(f"### Loading: ComfyUI-Manager ({version})")
2323

2424
required_comfyui_revision = 1793
@@ -96,6 +96,7 @@ def run_script(cmd, cwd='.'):
9696
js_path = os.path.join(comfy_path, "web", "extensions")
9797

9898
comfyui_manager_path = os.path.dirname(__file__)
99+
cache_dir = os.path.join(comfyui_manager_path, '.cache')
99100
local_db_model = os.path.join(comfyui_manager_path, "model-list.json")
100101
local_db_alter = os.path.join(comfyui_manager_path, "alter-list.json")
101102
local_db_custom_node_list = os.path.join(comfyui_manager_path, "custom-node-list.json")
@@ -484,6 +485,44 @@ def setup_environment():
484485
import urllib.request
485486

486487

488+
def simple_hash(input_string):
489+
hash_value = 0
490+
for char in input_string:
491+
hash_value = (hash_value * 31 + ord(char)) % (2**32)
492+
493+
return hash_value
494+
495+
496+
async def get_data_by_mode(mode, filename):
497+
try:
498+
if mode == "local":
499+
uri = os.path.join(comfyui_manager_path, filename)
500+
json_obj = await get_data(uri)
501+
else:
502+
uri = get_config()['channel_url'] + '/' + filename
503+
cache_uri = str(simple_hash(uri))+'_'+filename
504+
cache_uri = os.path.join(cache_dir, cache_uri)
505+
506+
if mode == "cache":
507+
if is_file_created_within_one_day(cache_uri):
508+
json_obj = await get_data(cache_uri)
509+
else:
510+
json_obj = await get_data(uri)
511+
with open(cache_uri, "w", encoding='utf-8') as file:
512+
json.dump(json_obj, file, indent=4, sort_keys=True)
513+
else:
514+
uri = get_config()['channel_url'] + '/' + filename
515+
json_obj = await get_data(uri)
516+
with open(cache_uri, "w", encoding='utf-8') as file:
517+
json.dump(json_obj, file, indent=4, sort_keys=True)
518+
except Exception as e:
519+
print(f"[ComfyUI-Manager] Due to a network error, switching to local mode.\n=> {filename}\n=> {e}")
520+
uri = os.path.join(comfyui_manager_path, filename)
521+
json_obj = await get_data(uri)
522+
523+
return json_obj
524+
525+
487526
def get_model_dir(data):
488527
if data['save_path'] != 'default':
489528
if '..' in data['save_path'] or data['save_path'].startswith('/'):
@@ -609,14 +648,20 @@ def process_custom_node(item):
609648
print(f"\x1b[2K\rUpdate check done.")
610649

611650

651+
def is_file_created_within_one_day(file_path):
652+
if not os.path.exists(file_path):
653+
return False
654+
655+
file_creation_time = os.path.getctime(file_path)
656+
current_time = datetime.datetime.now().timestamp()
657+
time_difference = current_time - file_creation_time
658+
659+
return time_difference <= 86400
660+
661+
612662
@server.PromptServer.instance.routes.get("/customnode/getmappings")
613663
async def fetch_customnode_mappings(request):
614-
if request.rel_url.query["mode"] == "local":
615-
uri = local_db_extension_node_mappings
616-
else:
617-
uri = get_config()['channel_url'] + '/extension-node-map.json'
618-
619-
json_obj = await get_data(uri)
664+
json_obj = await get_data_by_mode(request.rel_url.query["mode"], 'extension-node-map.json')
620665

621666
all_nodes = set()
622667
patterns = []
@@ -639,12 +684,8 @@ async def fetch_customnode_mappings(request):
639684
@server.PromptServer.instance.routes.get("/customnode/fetch_updates")
640685
async def fetch_updates(request):
641686
try:
642-
if request.rel_url.query["mode"] == "local":
643-
uri = local_db_custom_node_list
644-
else:
645-
uri = get_config()['channel_url'] + '/custom-node-list.json'
687+
json_obj = await get_data_by_mode(request.rel_url.query["mode"], 'custom-node-list.json')
646688

647-
json_obj = await get_data(uri)
648689
check_custom_nodes_installed(json_obj, True)
649690

650691
update_exists = any('custom_nodes' in json_obj and 'installed' in node and node['installed'] == 'Update' for node in
@@ -663,12 +704,8 @@ async def update_all(request):
663704
try:
664705
save_snapshot_with_postfix('autosave')
665706

666-
if request.rel_url.query["mode"] == "local":
667-
uri = local_db_custom_node_list
668-
else:
669-
uri = get_config()['channel_url'] + '/custom-node-list.json'
707+
json_obj = await get_data_by_mode(request.rel_url.query["mode"], 'custom-node-list.json')
670708

671-
json_obj = await get_data(uri)
672709
check_custom_nodes_installed(json_obj, do_update=True)
673710

674711
update_exists = any(item['installed'] == 'Update' for item in json_obj['custom_nodes'])
@@ -731,12 +768,11 @@ async def fetch_customnode_list(request):
731768

732769
if request.rel_url.query["mode"] == "local":
733770
channel = 'local'
734-
uri = local_db_custom_node_list
735771
else:
736772
channel = get_config()['channel_url']
737-
uri = channel + '/custom-node-list.json'
738773

739-
json_obj = await get_data(uri)
774+
json_obj = await get_data_by_mode(request.rel_url.query["mode"], 'custom-node-list.json')
775+
740776
check_custom_nodes_installed(json_obj, False, not skip_update)
741777

742778
for x in json_obj['custom_nodes']:
@@ -766,15 +802,8 @@ async def fetch_alternatives_list(request):
766802
else:
767803
skip_update = False
768804

769-
if request.rel_url.query["mode"] == "local":
770-
uri1 = local_db_alter
771-
uri2 = local_db_custom_node_list
772-
else:
773-
uri1 = get_config()['channel_url'] + '/alter-list.json'
774-
uri2 = get_config()['channel_url'] + '/custom-node-list.json'
775-
776-
alter_json = await get_data(uri1)
777-
custom_node_json = await get_data(uri2)
805+
alter_json = await get_data_by_mode(request.rel_url.query["mode"], 'alter-list.json')
806+
custom_node_json = await get_data_by_mode(request.rel_url.query["mode"], 'custom-node-list.json')
778807

779808
fileurl_to_custom_node = {}
780809

@@ -813,12 +842,8 @@ def process_model(item):
813842

814843
@server.PromptServer.instance.routes.get("/externalmodel/getlist")
815844
async def fetch_externalmodel_list(request):
816-
if request.rel_url.query["mode"] == "local":
817-
uri = local_db_model
818-
else:
819-
uri = get_config()['channel_url'] + '/model-list.json'
845+
json_obj = await get_data_by_mode(request.rel_url.query["mode"], 'model-list.json')
820846

821-
json_obj = await get_data(uri)
822847
check_model_installed(json_obj)
823848

824849
return web.json_response(json_obj, content_type='application/json')

custom-node-list.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@
14981498
},
14991499
{
15001500
"author": "rgthree",
1501-
"title": "rgthree's ComfyUi Nodes",
1501+
"title": "rgthree's ComfyUI Nodes",
15021502
"reference": "https://github.com/rgthree/rgthree-comfy",
15031503
"files": [
15041504
"https://github.com/rgthree/rgthree-comfy"
@@ -3179,6 +3179,26 @@
31793179
"install_type": "git-clone",
31803180
"description": "Nodes:FL Image Randomizer. The start of a pack that I will continue to build out to fill the gaps of nodes and functionality that I feel is missing in comfyUI"
31813181
},
3182+
{
3183+
"author": "zfkun",
3184+
"title": "ComfyUI_zfkun",
3185+
"reference": "https://github.com/zfkun/ComfyUI_zfkun",
3186+
"files": [
3187+
"https://github.com/zfkun/ComfyUI_zfkun"
3188+
],
3189+
"install_type": "git-clone",
3190+
"description": "Nodes: Preview Text, Text Translation."
3191+
},
3192+
{
3193+
"author": "80sVectorz",
3194+
"title": "ComfyUI-Static-Primitives",
3195+
"reference": "https://github.com/80sVectorz/ComfyUI-Static-Primitives",
3196+
"files": [
3197+
"https://github.com/80sVectorz/ComfyUI-Static-Primitives"
3198+
],
3199+
"install_type": "git-clone",
3200+
"description": "Adds Static Primitives to ComfyUI. Mostly to work with reroute nodes"
3201+
},
31823202
{
31833203
"author": "Ser-Hilary",
31843204
"title": "SDXL_sizing",

extension-node-map.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@
14291429
"RerouteTextForCLIPTextEncodeA1111"
14301430
],
14311431
{
1432+
"nodename_pattern": "- Ostris$",
14321433
"title_aux": "ComfyUI A1111-like Prompt Custom Node Solution"
14331434
}
14341435
],
@@ -2730,7 +2731,8 @@
27302731
"https://github.com/chflame163/ComfyUI_MSSpeech_TTS": [
27312732
[
27322733
"MicorsoftSpeech_TTS",
2733-
"Play Sound"
2734+
"Play Sound",
2735+
"Play Sound (loop)"
27342736
],
27352737
{
27362738
"title_aux": "ComfyUI_MSSpeech_TTS"
@@ -3506,6 +3508,9 @@
35063508
"https://github.com/jags111/ComfyUI_Jags_VectorMagic": [
35073509
[
35083510
"CircularVAEDecode",
3511+
"JagsCLIPSeg",
3512+
"JagsClipseg",
3513+
"JagsCombineMasks",
35093514
"SVG",
35103515
"YoloSEGdetectionNode",
35113516
"YoloSegNode",
@@ -4558,7 +4563,7 @@
45584563
"nickname": "rgthree",
45594564
"nodename_pattern": " \\(rgthree\\)$",
45604565
"title": "Comfy Nodes",
4561-
"title_aux": "rgthree's ComfyUi Nodes"
4566+
"title_aux": "rgthree's ComfyUI Nodes"
45624567
}
45634568
],
45644569
"https://github.com/richinsley/Comfy-LFO": [
@@ -5077,7 +5082,6 @@
50775082
"Random Line 4"
50785083
],
50795084
{
5080-
"nodename_pattern": "\\(mtb\\)$",
50815085
"title_aux": "Hakkun-ComfyUI-nodes"
50825086
}
50835087
],
@@ -5474,6 +5478,16 @@
54745478
"title_aux": "Cute Comfy"
54755479
}
54765480
],
5481+
"https://github.com/zfkun/ComfyUI_zfkun": [
5482+
[
5483+
"ZFPreviewText",
5484+
"ZFPreviewTextMultiline",
5485+
"ZFTextTranslation"
5486+
],
5487+
{
5488+
"title_aux": "ComfyUI_zfkun"
5489+
}
5490+
],
54775491
"https://github.com/zhuanqianfish/ComfyUI-EasyNode": [
54785492
[
54795493
"EasyCaptureNode",

js/a1111-alter-downloader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { ComfyDialog, $el } from "../../scripts/ui.js";
44
import { install_checked_custom_node, manager_instance, rebootAPI } from "./common.js";
55

66
async function getAlterList() {
7-
var mode = "url";
8-
if(manager_instance.local_mode_checkbox.checked)
9-
mode = "local";
7+
var mode = manager_instance.datasrc_combo.value;
108

119
var skip_update = "";
1210
if(manager_instance.update_check_checkbox.checked)

0 commit comments

Comments
 (0)