perf: harden quotas and reduce compression overhead
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
237899745
2026-07-25 23:10:59 +08:00
parent 49189d346b
commit 86da5cf1f5
15 changed files with 464 additions and 210 deletions

View File

@@ -569,14 +569,20 @@ async fn process_task_file(
ctx: TaskContext,
billing_ctx: Option<billing::BillingContext>,
) -> Result<(), AppError> {
if is_task_cancelled(&state, task_id).await? {
return Ok(());
}
let updated = sqlx::query(
"UPDATE task_files SET status = 'processing' WHERE id = $1 AND status = 'pending'",
r#"
UPDATE task_files AS f
SET status = 'processing'
FROM tasks AS t
WHERE f.id = $1
AND f.task_id = t.id
AND t.id = $2
AND f.status = 'pending'
AND t.status IN ('pending', 'processing')
"#,
)
.bind(file.id)
.bind(task_id)
.execute(&state.db)
.await
.map_err(|err| AppError::new(ErrorCode::Internal, "更新文件处理状态失败").with_source(err))?;
@@ -584,11 +590,6 @@ async fn process_task_file(
return Ok(());
}
if is_task_cancelled(&state, task_id).await? {
mark_file_failed(&state, task_id, file.id, "已取消").await?;
return Ok(());
}
let Some(input_path) = file.input_path.clone() else {
mark_file_failed(&state, task_id, file.id, "原文件不存在").await?;
return Ok(());
@@ -702,13 +703,6 @@ async fn process_task_file(
}
}
if is_task_cancelled(&state, task_id).await? {
let _ = storage::delete_object(&state, &stored_locator(&stored)).await;
mark_file_failed(&state, task_id, file.id, "已取消").await?;
let _ = tokio::fs::remove_file(&input_path).await;
return Ok(());
}
if let Err(err) = finalize_file(
&state,
&billing_ctx,
@@ -766,6 +760,9 @@ async fn finalize_file(
.map_err(|err| {
AppError::new(ErrorCode::Internal, "锁定任务状态失败").with_source(err)
})?;
if matches!(task_status.as_deref(), Some("cancelled")) {
return Err(AppError::new(ErrorCode::InvalidRequest, "已取消"));
}
if !matches!(task_status.as_deref(), Some("pending" | "processing")) {
return Err(AppError::new(ErrorCode::InvalidRequest, "任务已结束"));
}