mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-17 10:22:59 +08:00
optimize: async cache on startup
This commit is contained in:
parent
a762e60892
commit
fe9b5ea473
45
__init__.py
45
__init__.py
@ -18,11 +18,14 @@ import re
|
|||||||
import signal
|
import signal
|
||||||
import nodes
|
import nodes
|
||||||
|
|
||||||
version = "V1.10.4"
|
version = "V1.11"
|
||||||
print(f"### Loading: ComfyUI-Manager ({version})")
|
print(f"### Loading: ComfyUI-Manager ({version})")
|
||||||
|
|
||||||
required_comfyui_revision = 1793
|
required_comfyui_revision = 1793
|
||||||
|
|
||||||
|
|
||||||
|
cache_lock = threading.Lock()
|
||||||
|
|
||||||
def handle_stream(stream, prefix):
|
def handle_stream(stream, prefix):
|
||||||
stream.reconfigure(encoding=locale.getpreferredencoding(), errors='replace')
|
stream.reconfigure(encoding=locale.getpreferredencoding(), errors='replace')
|
||||||
for msg in stream:
|
for msg in stream:
|
||||||
@ -437,8 +440,9 @@ async def get_data(uri):
|
|||||||
async with session.get(uri) as resp:
|
async with session.get(uri) as resp:
|
||||||
json_text = await resp.text()
|
json_text = await resp.text()
|
||||||
else:
|
else:
|
||||||
with open(uri, "r", encoding="utf-8") as f:
|
with cache_lock:
|
||||||
json_text = f.read()
|
with open(uri, "r", encoding="utf-8") as f:
|
||||||
|
json_text = f.read()
|
||||||
|
|
||||||
json_obj = json.loads(json_text)
|
json_obj = json.loads(json_text)
|
||||||
return json_obj
|
return json_obj
|
||||||
@ -519,13 +523,15 @@ async def get_data_by_mode(mode, filename):
|
|||||||
json_obj = await get_data(cache_uri)
|
json_obj = await get_data(cache_uri)
|
||||||
else:
|
else:
|
||||||
json_obj = await get_data(uri)
|
json_obj = await get_data(uri)
|
||||||
with open(cache_uri, "w", encoding='utf-8') as file:
|
with cache_lock:
|
||||||
json.dump(json_obj, file, indent=4, sort_keys=True)
|
with open(cache_uri, "w", encoding='utf-8') as file:
|
||||||
|
json.dump(json_obj, file, indent=4, sort_keys=True)
|
||||||
else:
|
else:
|
||||||
uri = get_config()['channel_url'] + '/' + filename
|
uri = get_config()['channel_url'] + '/' + filename
|
||||||
json_obj = await get_data(uri)
|
json_obj = await get_data(uri)
|
||||||
with open(cache_uri, "w", encoding='utf-8') as file:
|
with cache_lock:
|
||||||
json.dump(json_obj, file, indent=4, sort_keys=True)
|
with open(cache_uri, "w", encoding='utf-8') as file:
|
||||||
|
json.dump(json_obj, file, indent=4, sort_keys=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ComfyUI-Manager] Due to a network error, switching to local mode.\n=> {filename}\n=> {e}")
|
print(f"[ComfyUI-Manager] Due to a network error, switching to local mode.\n=> {filename}\n=> {e}")
|
||||||
uri = os.path.join(comfyui_manager_path, filename)
|
uri = os.path.join(comfyui_manager_path, filename)
|
||||||
@ -1875,6 +1881,31 @@ async def share_art(request):
|
|||||||
}
|
}
|
||||||
}, content_type='application/json', status=200)
|
}, content_type='application/json', status=200)
|
||||||
|
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
async def default_cache_update():
|
||||||
|
async def get_cache(filename):
|
||||||
|
uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/' + filename
|
||||||
|
cache_uri = str(simple_hash(uri)) + '_' + filename
|
||||||
|
cache_uri = os.path.join(cache_dir, cache_uri)
|
||||||
|
|
||||||
|
json_obj = await get_data(uri)
|
||||||
|
|
||||||
|
with cache_lock:
|
||||||
|
with open(cache_uri, "w", encoding='utf-8') as file:
|
||||||
|
json.dump(json_obj, file, indent=4, sort_keys=True)
|
||||||
|
print(f"[ComfyUI-Manager] default cache updated: {uri}")
|
||||||
|
|
||||||
|
a = get_cache("custom-node-list.json")
|
||||||
|
b = get_cache("extension-node-map.json")
|
||||||
|
c = get_cache("model-list.json")
|
||||||
|
d = get_cache("alter-list.json")
|
||||||
|
|
||||||
|
await asyncio.gather(a, b, c, d)
|
||||||
|
|
||||||
|
threading.Thread(target=lambda: asyncio.run(default_cache_update())).start()
|
||||||
|
|
||||||
|
|
||||||
WEB_DIRECTORY = "js"
|
WEB_DIRECTORY = "js"
|
||||||
NODE_CLASS_MAPPINGS = {}
|
NODE_CLASS_MAPPINGS = {}
|
||||||
__all__ = ['NODE_CLASS_MAPPINGS']
|
__all__ = ['NODE_CLASS_MAPPINGS']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user