feat: do not enqueue phase 2 if not necessary (#12344)

This commit is contained in:
jif-oai
2026-02-20 17:21:45 +00:00
committed by GitHub
parent 5a30cd3f92
commit fd67aba114
2 changed files with 118 additions and 9 deletions

View File

@@ -498,7 +498,7 @@ WHERE excluded.source_updated_at >= stage1_outputs.source_updated_at
/// - sets `status='done'` and `last_success_watermark = input_watermark`
/// - deletes any existing `stage1_outputs` row for the thread
/// - enqueues/advances the global phase-2 job watermark using the claimed
/// `input_watermark`
/// `input_watermark` only when deleting an existing `stage1_outputs` row
pub async fn mark_stage1_job_succeeded_no_output(
&self,
thread_id: ThreadId,
@@ -548,7 +548,7 @@ WHERE kind = ? AND job_key = ? AND ownership_token = ?
.await?
.try_get::<i64, _>("input_watermark")?;
sqlx::query(
let deleted_rows = sqlx::query(
r#"
DELETE FROM stage1_outputs
WHERE thread_id = ?
@@ -556,9 +556,12 @@ WHERE thread_id = ?
)
.bind(thread_id.as_str())
.execute(&mut *tx)
.await?;
.await?
.rows_affected();
enqueue_global_consolidation_with_executor(&mut *tx, source_updated_at).await?;
if deleted_rows > 0 {
enqueue_global_consolidation_with_executor(&mut *tx, source_updated_at).await?;
}
tx.commit().await?;
Ok(true)