aboutsummaryrefslogtreecommitdiffstats
path: root/modules/hashes.py
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2023-01-14 12:55:40 +0000
committerAUTOMATIC <16777216c@gmail.com>2023-01-14 12:55:40 +0000
commit08c6f009a5ee92dd3218a942c08e8337c26352be (patch)
treea4398b52b1fc3cac9ec9a69e9098996ed18ca11b /modules/hashes.py
parentfebd2b722e80959b89a0e5966a159b4eb430c5a5 (diff)
downloadstable-diffusion-webui-gfx803-08c6f009a5ee92dd3218a942c08e8337c26352be.tar.gz
stable-diffusion-webui-gfx803-08c6f009a5ee92dd3218a942c08e8337c26352be.tar.bz2
stable-diffusion-webui-gfx803-08c6f009a5ee92dd3218a942c08e8337c26352be.zip
load hashes from cache for checkpoints that have them
add checkpoint hash to footer
Diffstat (limited to 'modules/hashes.py')
-rw-r--r--modules/hashes.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/modules/hashes.py b/modules/hashes.py
index ebfbd90c..14231771 100644
--- a/modules/hashes.py
+++ b/modules/hashes.py
@@ -42,23 +42,35 @@ def calculate_sha256(filename):
return hash_sha256.hexdigest()
-def sha256(filename, title):
+def sha256_from_cache(filename, title):
hashes = cache("hashes")
ondisk_mtime = os.path.getmtime(filename)
- if title in hashes:
- cached_sha256 = hashes[title].get("sha256", None)
- cached_mtime = hashes[title].get("mtime", 0)
+ if title not in hashes:
+ return None
+
+ cached_sha256 = hashes[title].get("sha256", None)
+ cached_mtime = hashes[title].get("mtime", 0)
+
+ if ondisk_mtime > cached_mtime or cached_sha256 is None:
+ return None
+
+ return cached_sha256
+
+
+def sha256(filename, title):
+ hashes = cache("hashes")
- if ondisk_mtime <= cached_mtime and cached_sha256 is not None:
- return cached_sha256
+ sha256_value = sha256_from_cache(filename, title)
+ if sha256_value is not None:
+ return sha256_value
print(f"Calculating sha256 for {filename}: ", end='')
sha256_value = calculate_sha256(filename)
print(f"{sha256_value}")
hashes[title] = {
- "mtime": ondisk_mtime,
+ "mtime": os.path.getmtime(filename),
"sha256": sha256_value,
}