Cache /object_info

If you have a lot of custom nodes installed, it can take a while to iterate through all of them.
This takes page reload from 5s to under 1s on my machine.

AFAIK new nodes are never added after startup, so the cache remains valid.
This commit is contained in:
Michael Abrahams 2024-04-24 21:38:55 -04:00
parent 8dc19e40d1
commit d783245e57

View File

@ -89,6 +89,8 @@ class PromptServer():
self.client_id = None
self.on_prompt_handlers = []
self.node_info_cache = None
@routes.get('/ws')
async def websocket_handler(request):
@ -408,14 +410,16 @@ class PromptServer():
@routes.get("/object_info")
async def get_object_info(request):
out = {}
for x in nodes.NODE_CLASS_MAPPINGS:
try:
out[x] = node_info(x)
except Exception as e:
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
logging.error(traceback.format_exc())
return web.json_response(out)
if self.node_info_cache is None:
self.node_info_cache = {}
for x in nodes.NODE_CLASS_MAPPINGS:
try:
self.node_info_cache[x] = node_info(x)
except Exception as e:
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
logging.error(traceback.format_exc())
return web.json_response(self.node_info_cache)
@routes.get("/object_info/{node_class}")
async def get_object_info_node(request):