diff options
author | Aarni Koskela <akx@iki.fi> | 2024-01-03 22:16:58 +0000 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2024-01-03 22:26:30 +0000 |
commit | d9034b48a526f0a0c3e8f0dbf7c171bf4f0597fd (patch) | |
tree | b01be238a08893afe6c5e5ebb58715c3860a2299 /modules/cache.py | |
parent | e4dcdcc9554d7ff56993f5019eb90fe4ddf1e2e7 (diff) | |
download | stable-diffusion-webui-gfx803-d9034b48a526f0a0c3e8f0dbf7c171bf4f0597fd.tar.gz stable-diffusion-webui-gfx803-d9034b48a526f0a0c3e8f0dbf7c171bf4f0597fd.tar.bz2 stable-diffusion-webui-gfx803-d9034b48a526f0a0c3e8f0dbf7c171bf4f0597fd.zip |
Avoid unnecessary `isfile`/`exists` calls
Diffstat (limited to 'modules/cache.py')
-rw-r--r-- | modules/cache.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/modules/cache.py b/modules/cache.py index 2d37e7b9..a9822a0e 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -62,16 +62,15 @@ def cache(subsection): if cache_data is None:
with cache_lock:
if cache_data is None:
- if not os.path.isfile(cache_filename):
+ try:
+ with open(cache_filename, "r", encoding="utf8") as file:
+ cache_data = json.load(file)
+ except FileNotFoundError:
+ cache_data = {}
+ except Exception:
+ os.replace(cache_filename, os.path.join(script_path, "tmp", "cache.json"))
+ print('[ERROR] issue occurred while trying to read cache.json, move current cache to tmp/cache.json and create new cache')
cache_data = {}
- else:
- try:
- with open(cache_filename, "r", encoding="utf8") as file:
- cache_data = json.load(file)
- except Exception:
- os.replace(cache_filename, os.path.join(script_path, "tmp", "cache.json"))
- print('[ERROR] issue occurred while trying to read cache.json, move current cache to tmp/cache.json and create new cache')
- cache_data = {}
s = cache_data.get(subsection, {})
cache_data[subsection] = s
|