diff --git a/app/assets/api/routes.py b/app/assets/api/routes.py index 2622fbe5d..55bbe7ded 100644 --- a/app/assets/api/routes.py +++ b/app/assets/api/routes.py @@ -1,3 +1,4 @@ +import asyncio import json import logging import os @@ -636,22 +637,12 @@ async def seed_assets(request: web.Request) -> web.Response: wait_param = request.query.get("wait", "").lower() should_wait = wait_param in ("true", "1", "yes") - # Temporarily enable seeder for explicit API calls (--disable-assets-autoscan - # only prevents the automatic startup scan, not manual triggers) - was_disabled = asset_seeder.is_disabled() - if was_disabled: - asset_seeder.enable() - started = asset_seeder.start(roots=valid_roots) if not started: - if was_disabled: - asset_seeder.disable() return web.json_response({"status": "already_running"}, status=409) if should_wait: - asset_seeder.wait() - if was_disabled: - asset_seeder.disable() + await asyncio.to_thread(asset_seeder.wait) status = asset_seeder.get_status() return web.json_response( { @@ -667,11 +658,6 @@ async def seed_assets(request: web.Request) -> web.Response: status=200, ) - # Re-disable after starting: the running thread doesn't check _disabled, - # so this only prevents new scans from auto-starting while this one runs. - if was_disabled: - asset_seeder.disable() - return web.json_response({"status": "started"}, status=202) diff --git a/comfy/cli_args.py b/comfy/cli_args.py index 13079c7bc..e9832acaf 100644 --- a/comfy/cli_args.py +++ b/comfy/cli_args.py @@ -232,7 +232,7 @@ database_default_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "user", "comfyui.db") ) parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.") -parser.add_argument("--disable-assets-autoscan", action="store_true", help="Disable asset scanning on startup for database synchronization.") +parser.add_argument("--enable-assets", action="store_true", help="Enable the assets system (API routes, database synchronization, and background scanning).") if comfy.options.args_parsing: args = parser.parse_args() diff --git a/comfy_api/feature_flags.py b/comfy_api/feature_flags.py index a90a5ca40..9f6918315 100644 --- a/comfy_api/feature_flags.py +++ b/comfy_api/feature_flags.py @@ -15,6 +15,7 @@ SERVER_FEATURE_FLAGS: dict[str, Any] = { "max_upload_size": args.max_upload_size * 1024 * 1024, # Convert MB to bytes "extension": {"manager": {"supports_v4": True}}, "node_replacements": True, + "assets": args.enable_assets, } diff --git a/main.py b/main.py index fc77edb7b..7b22d783e 100644 --- a/main.py +++ b/main.py @@ -359,10 +359,9 @@ def setup_database(): from app.database.db import init_db, dependencies_available if dependencies_available(): init_db() - if args.disable_assets_autoscan: - asset_seeder.disable() - elif asset_seeder.start(roots=("models", "input", "output"), prune_first=True, compute_hashes=True): - logging.info("Background asset scan initiated for models, input, output") + if args.enable_assets: + if asset_seeder.start(roots=("models", "input", "output"), prune_first=True, compute_hashes=True): + logging.info("Background asset scan initiated for models, input, output") except Exception as e: logging.error(f"Failed to initialize database. Please ensure you have installed the latest requirements. If the error persists, please report this as in future the database will be required: {e}") diff --git a/server.py b/server.py index 1067239f8..5cbcf0916 100644 --- a/server.py +++ b/server.py @@ -239,7 +239,8 @@ class PromptServer(): else args.front_end_root ) logging.info(f"[Prompt Server] web root: {self.web_root}") - register_assets_system(self.app, self.user_manager) + if args.enable_assets: + register_assets_system(self.app, self.user_manager) routes = web.RouteTableDef() self.routes = routes self.last_node_id = None diff --git a/tests-unit/assets_test/conftest.py b/tests-unit/assets_test/conftest.py index ef2ee98ac..986e56edf 100644 --- a/tests-unit/assets_test/conftest.py +++ b/tests-unit/assets_test/conftest.py @@ -108,7 +108,7 @@ def comfy_url_and_proc(comfy_tmp_base_dir: Path, request: pytest.FixtureRequest) "main.py", f"--base-directory={str(comfy_tmp_base_dir)}", f"--database-url={db_url}", - "--disable-assets-autoscan", + "--enable-assets", "--listen", "127.0.0.1", "--port",