fix(awooop): parallelize quality summary truth-chain fetch
All checks were successful
Code Review / ai-code-review (push) Successful in 22s
CD Pipeline / tests (push) Successful in 1m7s
CD Pipeline / build-and-deploy (push) Successful in 3m20s
CD Pipeline / post-deploy-checks (push) Successful in 1m14s

This commit is contained in:
Your Name
2026-05-18 10:27:32 +08:00
parent 168241e3c5
commit 5d10c8fbfe
2 changed files with 47 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ Telegram cards can be audited without guessing which subsystem owns the truth.
from __future__ import annotations
import asyncio
import json
from datetime import UTC, date, datetime, timedelta
from decimal import Decimal
@@ -24,6 +25,7 @@ logger = structlog.get_logger(__name__)
_MAX_ROWS = 100
_JSON_TEXT_FIELDS = {"gate_result", "source_envelope"}
_QUALITY_SUMMARY_CONCURRENCY = 8
def _clean(value: Any) -> Any:
@@ -1477,17 +1479,25 @@ async def fetch_automation_quality_summary(
},
)
records: list[dict[str, Any]] = []
for incident in incidents:
semaphore = asyncio.Semaphore(_QUALITY_SUMMARY_CONCURRENCY)
async def _quality_record(incident: dict[str, Any]) -> dict[str, Any] | None:
incident_id = str(incident.get("incident_id") or "")
if not incident_id:
continue
truth_chain = await fetch_truth_chain(source_id=incident_id, project_id=project_id)
records.append({
return None
async with semaphore:
truth_chain = await fetch_truth_chain(source_id=incident_id, project_id=project_id)
return {
"incident": truth_chain.get("incident") or incident,
"truth_status": truth_chain.get("truth_status") or {},
"automation_quality": truth_chain.get("automation_quality") or {},
})
}
records = [
record
for record in await asyncio.gather(*(_quality_record(incident) for incident in incidents))
if record is not None
]
summary = summarize_automation_quality_records(
project_id=project_id,