fix: Model hashing fixes (#62)

* make sure hashing is done only when the models are selected

* fix cache file not being written, if it did not exist

---------

Co-authored-by: Frost Ming <me@frostming.com>
This commit is contained in:
Sebastian Elsner
2025-11-10 09:42:29 +08:00
committed by GitHub
co-authored by Frost Ming
parent 521aca76ee
commit 705e82af4a
2 changed files with 22 additions and 6 deletions
+16 -5
View File
@@ -15,14 +15,14 @@ from fnmatch import fnmatch
from pathlib import Path
from typing import Any, Union
import folder_paths
from aiohttp import web
from server import PromptServer
from comfy_pack.hash import async_batch_get_sha256
from comfy_pack.model_helper import alookup_model_source
from comfy_pack.package import build_bento
import folder_paths
from server import PromptServer
ZPath = Union[Path, zipfile.Path]
TEMP_FOLDER = Path(__file__).parent.parent / "temp"
COMFY_PACK_DIR = Path(__file__).parent.parent / "src" / "comfy_pack"
@@ -136,12 +136,23 @@ async def _get_models(
for line in stdout.decode().splitlines()
if not os.path.basename(line.strip().strip('"').replace('\\\\', '/')).startswith(".")
]
# Only compute hashes for referenced models
to_include = []
if model_filter:
for m1 in model_filter:
for m2 in model_filenames:
if m1 in m2:
to_include.append(m2)
else:
to_include = model_filenames
model_hashes = await async_batch_get_sha256(
model_filenames,
to_include,
cache_only=not (ensure_sha or store_models),
)
for filename in model_filenames:
for filename in to_include:
# Skip if file doesn't exist
if not os.path.exists(filename):
continue
+6 -1
View File
@@ -113,7 +113,12 @@ async def async_batch_get_sha256(
try:
with SHA_CACHE_FILE.open("r") as f:
cache = json.load(f)
cache.update(new_cache)
except (IOError, OSError):
cache = {}
cache.update(new_cache)
try:
with SHA_CACHE_FILE.open("w") as f:
json.dump(cache, f, indent=2)
except (IOError, OSError):