From bc9b6252215428f21671085630e891600c5b9ffe Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Fri, 2 Feb 2024 01:11:50 +0100 Subject: [PATCH] feat: add hash cache to metadata --- modules/metadata.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/metadata.py b/modules/metadata.py index aa0925d6..60b1dd4c 100644 --- a/modules/metadata.py +++ b/modules/metadata.py @@ -7,13 +7,23 @@ from PIL import Image import modules.config import fooocus_version # import advanced_parameters -from modules.util import quote, unquote, extract_styles_from_prompt, is_json from modules.flags import MetadataScheme, Performance, Steps, lora_count_with_lcm +from modules.util import quote, unquote, extract_styles_from_prompt, is_json, calculate_sha256 re_param_code = r'\s*(\w[\w \-/]+):\s*("(?:\\.|[^\\"])+"|[^,]*)(?:,|$)' re_param = re.compile(re_param_code) re_imagesize = re.compile(r"^(\d+)x(\d+)$") +hash_cache = {} + + +def get_sha256(filepath): + global hash_cache + + if filepath not in hash_cache: + hash_cache[filepath] = calculate_sha256(filepath) + + return hash_cache[filepath] class MetadataParser(ABC): @abstractmethod