Three problems with the previous server-side approach: 1. wildcard_choices() called get_wildcard_manager() (full disk scan) on every INPUT_TYPES call, causing massive slowdown with large datasets. 2. Node execution went from ~0.2s to ~4.33s for the same reason. 3. Appending to the template server-side is wrong — selection should insert __name__ into the template textbox widget in the browser. Fix: - Remove wildcard_append from all Python nodes and wildcard_choices() from wildcards.py, restoring original execution performance. - Add GET /dynamic_prompts/wildcards API route returning list_names() as JSON (loaded once per session, not per execution). - Add web/wildcards.js extension that fetches the wildcard list once, injects a serialize:false COMBO widget into each node, and on selection appends __name__ to the template widget then resets. - Register WEB_DIRECTORY = "web" in __init__.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import sys
|
|
from pathlib import Path
|
|
|
|
_here = Path(__file__).parent
|
|
|
|
try:
|
|
from .src.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
|
except ImportError:
|
|
# Fallback for environments where this file is loaded without a parent package
|
|
# (e.g., pytest package-setup walker). Add the project root to sys.path so that
|
|
# absolute imports of src.* work.
|
|
if str(_here) not in sys.path:
|
|
sys.path.insert(0, str(_here))
|
|
from src.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS # type: ignore[import-not-found]
|
|
|
|
WILDCARDS_PATH = _here / "wildcards"
|
|
WEB_DIRECTORY = "web"
|
|
|
|
try:
|
|
import folder_paths # type: ignore[import-not-found]
|
|
|
|
_models_wildcards = Path(folder_paths.models_dir) / "wildcards"
|
|
folder_paths.add_model_folder_path("wildcards", str(_models_wildcards))
|
|
except (ImportError, AttributeError):
|
|
pass
|
|
|
|
try:
|
|
from aiohttp.web import json_response
|
|
from server import PromptServer # type: ignore[import-not-found]
|
|
from src.wildcards import get_wildcard_manager
|
|
|
|
@PromptServer.instance.routes.get("/dynamic_prompts/wildcards")
|
|
async def _list_wildcards(_request): # type: ignore[misc]
|
|
return json_response(get_wildcard_manager().list_names())
|
|
|
|
except (ImportError, AttributeError):
|
|
pass
|
|
|
|
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
|