3D 产物哈希挪到 blocking 线程池

- server-rs/crates/api-server/src/tripo3d/storage.rs:上传前对最大 512 MiB 的产物做 sha256 会占住一个 Tokio worker,改成 spawn_blocking 并把 bytes 原样带回(不做整块复制),失败按 500 收口
This commit is contained in:
2026-09-24 17:56:51 +08:00
parent f82eba4c94
commit 7a4ccb8bfe
@@ -113,7 +113,19 @@ pub(crate) async fn store_model3d_artifact(
.ok_or_else(|| oss_unavailable("OSS 未完成环境变量配置,无法写入 3D 产物。"))?;
let http_client = state.editor_oss_http_client();
let content_type = resolve_artifact_content_type(content_type, slot, bytes.as_slice())?;
let sha256 = sha256_hex(bytes.as_slice());
// 模型产物上限是 512 MiB,同步哈希会把一个 Tokio worker 占住几百毫秒,拖慢同一运行时上的
// 其它任务。挪到 blocking 线程池,并让任务把 bytes 原样带回来,省掉一次整块复制。
let (sha256, bytes) = tokio::task::spawn_blocking(move || {
let sha256 = sha256_hex(bytes.as_slice());
(sha256, bytes)
})
.await
.map_err(|error| {
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_details(json!({
"provider": TRIPO_PROVIDER,
"message": format!("3D 产物哈希任务失败:{error}"),
}))
})?;
let extension = slot
.artifact_extension(content_type.as_str())
.ok_or_else(|| unsupported_artifact_content_type(content_type.as_str(), slot))?;