fix(api): bound ansible backfill query cost
Some checks failed
Code Review / ai-code-review (push) Successful in 21s
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled

This commit is contained in:
Your Name
2026-06-27 14:10:17 +08:00
parent 824a56029d
commit f791107938
4 changed files with 10 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ async def _fetch_missing_candidate_incidents(
scan_limit: int,
) -> list[dict[str, Any]]:
async with get_db_context(project_id) as db:
await db.execute(text("SET LOCAL statement_timeout = '5000ms'"))
result = await db.execute(
text("""
SELECT
@@ -69,6 +70,7 @@ async def _fetch_missing_candidate_incidents(
SELECT 1
FROM automation_operation_log existing
WHERE existing.operation_type = 'ansible_candidate_matched'
AND existing.created_at >= NOW() - (:window_hours * INTERVAL '1 hour')
AND existing.input ->> 'executor' = 'ansible'
AND coalesce(existing.incident_id::text, existing.input ->> 'incident_id') = incidents.incident_id::text
)