From 705e82af4aee2680f05e18d3ff0cfb094a911053 Mon Sep 17 00:00:00 2001 From: Sebastian Elsner <902798+sebastianelsner@users.noreply.github.com> Date: Mon, 10 Nov 2025 02:42:29 +0100 Subject: [PATCH] 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 --- nodes/api.py | 21 ++++++++++++++++----- src/comfy_pack/hash.py | 7 ++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nodes/api.py b/nodes/api.py index d2ec687..ef1af18 100644 --- a/nodes/api.py +++ b/nodes/api.py @@ -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 diff --git a/src/comfy_pack/hash.py b/src/comfy_pack/hash.py index ff79528..b8744b4 100644 --- a/src/comfy_pack/hash.py +++ b/src/comfy_pack/hash.py @@ -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):