mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
startup sequence optimizations
Signed-off-by: vladmandic <mandic00@live.com>
This commit is contained in:
+10
-7
@@ -1,9 +1,11 @@
|
||||
import hashlib
|
||||
import os.path
|
||||
from rich import progress, errors
|
||||
from modules import shared
|
||||
from installer import log, console
|
||||
from modules.json_helpers import readfile, writefile
|
||||
from modules.paths import data_path
|
||||
|
||||
|
||||
cache_filename = os.path.join(data_path, "cache.json")
|
||||
cache_data = None
|
||||
progress_ok = True
|
||||
@@ -12,17 +14,17 @@ progress_ok = True
|
||||
def init_cache():
|
||||
global cache_data # pylint: disable=global-statement
|
||||
if cache_data is None:
|
||||
cache_data = {} if not os.path.isfile(cache_filename) else shared.readfile(cache_filename, lock=True, as_type="dict")
|
||||
cache_data = {} if not os.path.isfile(cache_filename) else readfile(cache_filename, lock=True, as_type="dict")
|
||||
|
||||
|
||||
def dump_cache():
|
||||
shared.writefile(cache_data, cache_filename)
|
||||
writefile(cache_data, cache_filename)
|
||||
|
||||
|
||||
def cache(subsection):
|
||||
global cache_data # pylint: disable=global-statement
|
||||
if cache_data is None:
|
||||
cache_data = {} if not os.path.isfile(cache_filename) else shared.readfile(cache_filename, lock=True, as_type="dict")
|
||||
cache_data = {} if not os.path.isfile(cache_filename) else readfile(cache_filename, lock=True, as_type="dict")
|
||||
s = cache_data.get(subsection, {})
|
||||
cache_data[subsection] = s
|
||||
return s
|
||||
@@ -35,11 +37,11 @@ def calculate_sha256(filename, quiet=False):
|
||||
if not quiet:
|
||||
if progress_ok:
|
||||
try:
|
||||
with progress.open(filename, 'rb', description=f'[cyan]Calculating hash: [yellow]{filename}', auto_refresh=True, console=shared.console) as f:
|
||||
with progress.open(filename, 'rb', description=f'[cyan]Calculating hash: [yellow]{filename}', auto_refresh=True, console=console) as f:
|
||||
for chunk in iter(lambda: f.read(blksize), b""):
|
||||
hash_sha256.update(chunk)
|
||||
except errors.LiveError:
|
||||
shared.log.warning('Hash: attempting to use function in a thread')
|
||||
log.warning('Hash: attempting to use function in a thread')
|
||||
progress_ok = False
|
||||
if not progress_ok:
|
||||
with open(filename, 'rb') as f:
|
||||
@@ -65,6 +67,7 @@ def sha256_from_cache(filename, title, use_addnet_hash=False):
|
||||
|
||||
|
||||
def sha256(filename, title, use_addnet_hash=False):
|
||||
from modules import shared
|
||||
global progress_ok # pylint: disable=global-statement
|
||||
hashes = cache("hashes-addnet") if use_addnet_hash else cache("hashes")
|
||||
sha256_value = sha256_from_cache(filename, title, use_addnet_hash)
|
||||
@@ -81,7 +84,7 @@ def sha256(filename, title, use_addnet_hash=False):
|
||||
with progress.open(filename, 'rb', description=f'[cyan]Calculating hash: [yellow]{filename}', auto_refresh=True, console=shared.console) as f:
|
||||
sha256_value = addnet_hash_safetensors(f)
|
||||
except errors.LiveError:
|
||||
shared.log.warning('Hash: attempting to use function in a thread')
|
||||
log.warning('Hash: attempting to use function in a thread')
|
||||
progress_ok = False
|
||||
if not progress_ok:
|
||||
with open(filename, 'rb') as f:
|
||||
|
||||
Reference in New Issue
Block a user