mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-19 21:08:19 +08:00
Merge 7f747f0e68 into 1d1099bea0
This commit is contained in:
commit
63ddb42544
@ -125,8 +125,6 @@ class ModelFileManager:
|
|||||||
return None
|
return None
|
||||||
if not os.path.isdir(folder):
|
if not os.path.isdir(folder):
|
||||||
return None
|
return None
|
||||||
if os.path.getmtime(folder) != model_file_list_cache[1]:
|
|
||||||
return None
|
|
||||||
for x in model_file_list_cache[1]:
|
for x in model_file_list_cache[1]:
|
||||||
time_modified = model_file_list_cache[1][x]
|
time_modified = model_file_list_cache[1][x]
|
||||||
folder = x
|
folder = x
|
||||||
@ -146,6 +144,11 @@ class ModelFileManager:
|
|||||||
result: list[str] = []
|
result: list[str] = []
|
||||||
dirs: dict[str, float] = {}
|
dirs: dict[str, float] = {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
dirs[directory] = os.path.getmtime(directory)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.warning(f"Warning: Unable to access {directory}. Skipping this path.")
|
||||||
|
|
||||||
for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
|
for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
|
||||||
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
||||||
if not include_hidden_files:
|
if not include_hidden_files:
|
||||||
|
|||||||
29
tests-unit/app_test/model_file_cache_test.py
Normal file
29
tests-unit/app_test/model_file_cache_test.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from app.model_manager import ModelFileManager
|
||||||
|
|
||||||
|
|
||||||
|
class TestModelFileListCache:
|
||||||
|
def test_cache_is_reused_when_unchanged(self, tmp_path):
|
||||||
|
sub = tmp_path / "sub"
|
||||||
|
sub.mkdir()
|
||||||
|
(sub / "m.safetensors").write_bytes(b"x")
|
||||||
|
|
||||||
|
mgr = ModelFileManager()
|
||||||
|
out = mgr.recursive_search_models_(str(tmp_path), 0)
|
||||||
|
mgr.set_cache(str(tmp_path), out)
|
||||||
|
|
||||||
|
# nothing changed, so the cached result must be returned instead of None
|
||||||
|
assert mgr.cache_model_file_list_(str(tmp_path)) is out
|
||||||
|
|
||||||
|
def test_cache_invalidated_when_top_folder_changes(self, tmp_path):
|
||||||
|
mgr = ModelFileManager()
|
||||||
|
out = mgr.recursive_search_models_(str(tmp_path), 0)
|
||||||
|
mgr.set_cache(str(tmp_path), out)
|
||||||
|
assert mgr.cache_model_file_list_(str(tmp_path)) is out
|
||||||
|
|
||||||
|
# a file added directly under the top folder changes its mtime, which must
|
||||||
|
# invalidate the cache (the top folder is tracked, not just subfolders)
|
||||||
|
bumped = os.path.getmtime(str(tmp_path)) + 100
|
||||||
|
os.utime(str(tmp_path), (bumped, bumped))
|
||||||
|
assert mgr.cache_model_file_list_(str(tmp_path)) is None
|
||||||
Loading…
Reference in New Issue
Block a user