mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-19 19:03:51 +00:00
Add folder content caching
This commit is contained in:
parent
82c3afe077
commit
d8eae1b241
@ -13,8 +13,19 @@ from typing import Literal
|
|||||||
|
|
||||||
class OutputManager:
|
class OutputManager:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
self.cache: dict[str, tuple[list, float]] = {}
|
||||||
self.output_uri = folder_paths.get_output_directory()
|
self.output_uri = folder_paths.get_output_directory()
|
||||||
|
|
||||||
|
def get_cache(self, key: str):
|
||||||
|
return self.cache.get(key, ([], 0))
|
||||||
|
|
||||||
|
def set_cache(self, key: str, value: tuple[list, float]):
|
||||||
|
self.cache[key] = value
|
||||||
|
|
||||||
|
def rm_cache(self, key: str):
|
||||||
|
if key in self.cache:
|
||||||
|
del self.cache[key]
|
||||||
|
|
||||||
def add_routes(self, routes) -> None:
|
def add_routes(self, routes) -> None:
|
||||||
@routes.get("/output{pathname:.*}")
|
@routes.get("/output{pathname:.*}")
|
||||||
async def get_output_file_or_files(request):
|
async def get_output_file_or_files(request):
|
||||||
@ -53,6 +64,7 @@ class OutputManager:
|
|||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
elif os.path.isdir(filepath):
|
elif os.path.isdir(filepath):
|
||||||
shutil.rmtree(filepath)
|
shutil.rmtree(filepath)
|
||||||
|
self.rm_cache(filepath)
|
||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return web.Response(status=500)
|
return web.Response(status=500)
|
||||||
@ -61,6 +73,12 @@ class OutputManager:
|
|||||||
return f"{self.output_uri}/{pathname}"
|
return f"{self.output_uri}/{pathname}"
|
||||||
|
|
||||||
def get_folder_items(self, folder: str):
|
def get_folder_items(self, folder: str):
|
||||||
|
result, m_time = self.get_cache(folder)
|
||||||
|
folder_m_time = os.path.getmtime(folder)
|
||||||
|
|
||||||
|
if folder_m_time == m_time:
|
||||||
|
return result
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
def get_file_info(entry: os.DirEntry[str]):
|
def get_file_info(entry: os.DirEntry[str]):
|
||||||
@ -87,6 +105,7 @@ class OutputManager:
|
|||||||
continue
|
continue
|
||||||
result.append(file_info)
|
result.append(file_info)
|
||||||
|
|
||||||
|
self.set_cache(folder, (result, os.path.getmtime(folder)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def assert_file_type(self, filename: str, content_types: Literal["image", "video", "audio"]):
|
def assert_file_type(self, filename: str, content_types: Literal["image", "video", "audio"]):
|
||||||
|
Loading…
Reference in New Issue
Block a user