From ba90c6065c07b6c4dd76f955e341fb1995a94ddb Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Thu, 3 Oct 2024 13:11:22 -0700 Subject: [PATCH] pre-scan model lists --- folder_paths.py | 15 ++++++++++++++- main.py | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/folder_paths.py b/folder_paths.py index c4ff5a91e..d4889abd8 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -5,6 +5,7 @@ import os import time import mimetypes import logging +import time from typing import Set, List, Dict, Tuple, Literal from collections.abc import Collection from concurrent.futures import ThreadPoolExecutor @@ -214,6 +215,18 @@ def get_folder_paths(folder_name: str) -> list[str]: folder_name = map_legacy(folder_name) return folder_names_and_paths[folder_name][0][:] + +def prebuild_lists(): + start_time = time.time() + calls = [] + for folder_name in folder_names_and_paths: + calls.append(async_executor.submit(lambda: get_filename_list(folder_name))) + while len(calls) > 0: + calls.pop().result() + end_time = time.time() + logging.info("Scanned model lists in {:.2f} seconds".format(end_time - start_time)) + + def recursive_search(directory: str, excluded_dir_names: list[str] | None=None) -> tuple[list[str], dict[str, float]]: if not os.path.isdir(directory): return [], {} @@ -261,11 +274,11 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None) logging.debug("found {} files".format(len(result))) return result, dirs + def filter_files_extensions(files: Collection[str], extensions: Collection[str]) -> list[str]: return sorted(list(filter(lambda a: os.path.splitext(a)[-1].lower() in extensions or len(extensions) == 0, files))) - def get_full_path(folder_name: str, filename: str) -> str | None: global folder_names_and_paths folder_name = map_legacy(folder_name) diff --git a/main.py b/main.py index 3f5e2137e..09ff6355f 100644 --- a/main.py +++ b/main.py @@ -212,6 +212,8 @@ if __name__ == "__main__": nodes.init_extra_nodes(init_custom_nodes=not args.disable_all_custom_nodes) + folder_paths.prebuild_lists() + cuda_malloc_warning() server.add_routes()