Decouple orphan pruning from asset seeding

- Remove automatic pruning from scan loop to prevent partial scans from
  deleting assets belonging to other roots
- Add get_all_known_prefixes() helper to get prefixes for all root types
- Add prune_orphans() method to AssetSeeder for explicit pruning
- Add prune_first parameter to start() for optional pre-scan pruning
- Add POST /api/assets/prune endpoint for explicit pruning via API
- Update main.py startup to use prune_first=True for full startup scans
- Add tests for new prune_orphans functionality

Fixes issue where a models-only scan would delete all input/output assets.

Amp-Thread-ID: https://ampcode.com/threads/T-019c2ba0-e004-7229-81bf-452b2f7f57a1
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Luke Mino-Altherr
2026-02-04 19:38:29 -08:00
parent 3a096a08ae
commit 7c85a421ac
5 changed files with 150 additions and 24 deletions

View File

@@ -357,8 +357,8 @@ def setup_database():
if dependencies_available():
init_db()
if not args.disable_assets_autoscan:
if asset_seeder.start(roots=("models",)):
logging.info("Background asset scan initiated for models")
if asset_seeder.start(roots=("models", "input", "output"), prune_first=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}")