From 2a50614c11a9da9f78c5c9577dd85cce0bd1a20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 12 Sep 2026 10:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=88=86=E7=A6=BB=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E9=98=BB=E5=A1=9E=20I/O=20=E7=A7=BB=E5=87=BA=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 spawn_blocking 状态读取封装 sidecar 目录创建改用阻塞任务执行 --- .../commands/separation/persistence.rs | 6 +++++ .../commands/separation/workflow/mod.rs | 26 ++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs index a2f0728c4..00221e9a8 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs @@ -159,6 +159,12 @@ pub fn read_separation_state(path: &Path) -> Result { Ok(state) } +pub async fn read_separation_state_async(path: PathBuf) -> Result { + tokio::task::spawn_blocking(move || read_separation_state(&path)) + .await + .map_err(|error| format!("读取 separation state 任务失败:{error}"))? +} + pub fn separation_dto(state: &SeparationState) -> SeparationDTO { app_log!( "ui_separation.dto bound_nodes={} problematic_nodes={} remaining_trees={}", diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs index fb1c1e4dd..7a24146fc 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs @@ -9,7 +9,7 @@ pub use patch::apply_batch_patch; use self::batch::next_image_batch_with_size; use super::model::*; use super::persistence::{ - project_relative_path, read_separation_state, separation_dto, separation_sidecar_dir, + project_relative_path, read_separation_state_async, separation_dto, separation_sidecar_dir, separation_state_path, write_separation_state, }; use super::prompt::gen_extract_prompt; @@ -42,7 +42,13 @@ pub(crate) async fn separate_ui_impl( ); error })?; - fs::create_dir_all(&sidecar).map_err(|error| { + tokio::task::spawn_blocking({ + let sidecar = sidecar.clone(); + move || fs::create_dir_all(sidecar) + }) + .await + .map_err(|error| format!("创建 separation sidecar 任务失败:{error}"))? + .map_err(|error| { app_log!( "ui_separation.error stage=sidecar_create asset_id={} error={error}", asset_id @@ -53,13 +59,15 @@ pub(crate) async fn separate_ui_impl( let restored = state_path.exists(); let mut separation = if restored { app_log!("ui_separation.state_restore.start asset_id={asset_id}"); - read_separation_state(&state_path).map_err(|error| { - app_log!( - "ui_separation.error stage=state_restore asset_id={} error={error}", - asset_id - ); - error - })? + read_separation_state_async(state_path.clone()) + .await + .map_err(|error| { + app_log!( + "ui_separation.error stage=state_restore asset_id={} error={error}", + asset_id + ); + error + })? } else { app_log!("ui_separation.state_construct.start asset_id={asset_id}"); super::tree::construct_separation_state(&state)