From e1b0ab5c3fcdb3ffd49b81b59b2aef43bb92f115 Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 23 Jan 2026 17:27:04 +0800 Subject: [PATCH] feat(app_asset_service): implement asynchronous file deletion in asset management - Added a threaded function to handle the deletion of storage files asynchronously after asset removal. - Updated the asset removal logic to include a call to the new deletion function, improving performance and responsiveness during asset management operations. --- api/services/app_asset_service.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/api/services/app_asset_service.py b/api/services/app_asset_service.py index 694342dd98..817756bd6a 100644 --- a/api/services/app_asset_service.py +++ b/api/services/app_asset_service.py @@ -1,4 +1,5 @@ import logging +import threading from uuid import uuid4 from sqlalchemy.orm import Session @@ -288,18 +289,23 @@ class AppAssetService: removed_ids = tree.remove(node_id) except TreeNodeNotFoundError as e: raise AppAssetNodeNotFoundError(str(e)) from e - - for nid in removed_ids: - storage_key = AssetPaths.draft_file(app_model.tenant_id, app_model.id, nid) - try: - AppAssetService.assets_storage().delete(storage_key) - except Exception: - logger.warning("Failed to delete storage file %s", storage_key, exc_info=True) - assets.asset_tree = tree assets.updated_by = account_id session.commit() + # FIXME(Mairuis): sync deletion queue + def _delete_file_from_storage(tenant_id: str, app_id: str, node_ids: list[str]) -> None: + for nid in removed_ids: + storage_key = AssetPaths.draft_file(app_model.tenant_id, app_model.id, nid) + try: + AppAssetService.assets_storage().delete(storage_key) + except Exception: + logger.warning("Failed to delete storage file %s", storage_key, exc_info=True) + + threading.Thread( + target=lambda: _delete_file_from_storage(app_model.tenant_id, app_model.id, removed_ids) + ).start() + @staticmethod def publish(session: Session, app_model: App, account_id: str, workflow_id: str) -> AppAssets: tenant_id = app_model.tenant_id