startup sequence optimizations

Signed-off-by: vladmandic <mandic00@live.com>
This commit is contained in:
vladmandic
2026-01-03 07:54:05 +01:00
parent b4ac004076
commit f6289206d8
6 changed files with 52 additions and 33 deletions
+10 -7
View File
@@ -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: