perf(doi): 13x speedup for /repos/doi/summary (108s → ~6s)

Two fixes:
1. skip_consistency=True in summary mode — omits C7/C13 subprocess calls
   (consistency_check.py) which were the main bottleneck (32 spawns for 16 repos).
   Full check still available per-repo via GET /repos/{slug}/doi.
2. asyncio.gather — all repos evaluated in parallel instead of sequentially.

Also: rename Repositories page title from "Repos" to "Repositories".

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 01:29:27 +01:00
parent 5eeeeeb6c4
commit 27e755815f
3 changed files with 42 additions and 31 deletions

View File

@@ -110,7 +110,11 @@ async def _run_consistency(repo_slug: str, api_base: str) -> tuple[int, int, int
return fail, warn, info return fail, warn, info
async def evaluate(repo: dict, api_base: str = "http://127.0.0.1:8000") -> DoIReport: async def evaluate(
repo: dict,
api_base: str = "http://127.0.0.1:8000",
skip_consistency: bool = False,
) -> DoIReport:
slug = repo.get("slug", "unknown") slug = repo.get("slug", "unknown")
results: list[CriterionResult] = [] results: list[CriterionResult] = []
@@ -171,14 +175,17 @@ async def evaluate(repo: dict, api_base: str = "http://127.0.0.1:8000") -> DoIRe
_r("C6", "CLAUDE.md present", "standard", "fail", "CLAUDE.md not found at repo root") _r("C6", "CLAUDE.md present", "standard", "fail", "CLAUDE.md not found at repo root")
# C7: workplan convention — consistency check 0 FAIL # C7: workplan convention — consistency check 0 FAIL
try: if skip_consistency:
fail, warn, _ = await _run_consistency(slug, api_base) _r("C7", "Workplan convention (0 FAIL)", "standard", "skip", "Not checked in summary mode — use /repos/{slug}/doi for full check")
if fail == 0: else:
_r("C7", "Workplan convention (0 FAIL)", "standard", "pass", f"consistency: {fail} fail / {warn} warn") try:
else: fail, warn, _ = await _run_consistency(slug, api_base)
_r("C7", "Workplan convention (0 FAIL)", "standard", "fail", f"consistency: {fail} fail / {warn} warn") if fail == 0:
except Exception as e: _r("C7", "Workplan convention (0 FAIL)", "standard", "pass", f"consistency: {fail} fail / {warn} warn")
_r("C7", "Workplan convention (0 FAIL)", "standard", "skip", f"Could not run consistency check: {e}") else:
_r("C7", "Workplan convention (0 FAIL)", "standard", "fail", f"consistency: {fail} fail / {warn} warn")
except Exception as e:
_r("C7", "Workplan convention (0 FAIL)", "standard", "skip", f"Could not run consistency check: {e}")
# C8: SBOM ingested # C8: SBOM ingested
last_sbom = repo.get("last_sbom_at") last_sbom = repo.get("last_sbom_at")
@@ -251,21 +258,21 @@ async def evaluate(repo: dict, api_base: str = "http://127.0.0.1:8000") -> DoIRe
"CLAUDE.md has no kaizen agent reference") "CLAUDE.md has no kaizen agent reference")
# C13: consistency check clean (0 FAIL, 0 WARN — C-12 exempt) # C13: consistency check clean (0 FAIL, 0 WARN — C-12 exempt)
try: if skip_consistency:
fail, warn, _ = await _run_consistency(slug, api_base) _r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "skip", "Not checked in summary mode — use /repos/{slug}/doi for full check")
# C-12 warns are legacy DB-only tasks — deduct them from warn count else:
c12_count = await _get(api_base, "/tasks/", {"workstream_id": None}) or [] try:
# Use raw counts from the script output fail, warn, _ = await _run_consistency(slug, api_base)
if fail == 0 and warn == 0: if fail == 0 and warn == 0:
_r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "pass") _r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "pass")
elif fail == 0 and warn > 0: elif fail == 0 and warn > 0:
_r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "warn", _r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "warn",
f"{warn} warn(s) — C-12 legacy tasks may be exempt") f"{warn} warn(s) — C-12 legacy tasks may be exempt")
else: else:
_r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "fail", _r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "fail",
f"{fail} fail(s), {warn} warn(s)") f"{fail} fail(s), {warn} warn(s)")
except Exception as e: except Exception as e:
_r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "skip", f"Could not run: {e}") _r("C13", "Consistency check clean (0 FAIL/WARN)", "full", "skip", f"Could not run: {e}")
# C14: host paths registered # C14: host paths registered
host_paths = repo.get("host_paths") or {} host_paths = repo.get("host_paths") or {}

View File

@@ -1,3 +1,4 @@
import asyncio
import uuid import uuid
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
@@ -80,8 +81,7 @@ async def doi_summary(session: AsyncSession = Depends(get_session)) -> list[DoIS
domain_result = await session.execute(select(Domain)) domain_result = await session.execute(select(Domain))
domain_map = {d.id: d.slug for d in domain_result.scalars().all()} domain_map = {d.id: d.slug for d in domain_result.scalars().all()}
entries: list[DoISummaryEntry] = [] async def _check_one(repo: ManagedRepo) -> DoISummaryEntry:
for repo in repos:
repo_dict = { repo_dict = {
"slug": repo.slug, "slug": repo.slug,
"domain_slug": domain_map.get(repo.domain_id), "domain_slug": domain_map.get(repo.domain_id),
@@ -90,8 +90,10 @@ async def doi_summary(session: AsyncSession = Depends(get_session)) -> list[DoIS
"host_paths": repo.host_paths or {}, "host_paths": repo.host_paths or {},
"last_sbom_at": str(repo.last_sbom_at) if repo.last_sbom_at else None, "last_sbom_at": str(repo.last_sbom_at) if repo.last_sbom_at else None,
} }
report = await _doi_evaluate(repo_dict) # skip_consistency=True: omits C7/C13 subprocess calls for speed.
entries.append(DoISummaryEntry( # The full check is available via GET /repos/{slug}/doi.
report = await _doi_evaluate(repo_dict, skip_consistency=True)
return DoISummaryEntry(
repo_slug=repo.slug, repo_slug=repo.slug,
domain_slug=domain_map.get(repo.domain_id), domain_slug=domain_map.get(repo.domain_id),
tier=report.tier, tier=report.tier,
@@ -99,7 +101,9 @@ async def doi_summary(session: AsyncSession = Depends(get_session)) -> list[DoIS
standard_pass=report.standard_pass, standard_pass=report.standard_pass,
full_pass=report.full_pass, full_pass=report.full_pass,
checked_at=report.checked_at, checked_at=report.checked_at,
)) )
entries: list[DoISummaryEntry] = list(await asyncio.gather(*[_check_one(r) for r in repos]))
tier_order = {"none": 0, "core": 1, "standard": 2, "full": 3} tier_order = {"none": 0, "core": 1, "standard": 2, "full": 3}
entries.sort(key=lambda e: tier_order.get(e.tier, 0)) entries.sort(key=lambda e: tier_order.get(e.tier, 0))

View File

@@ -1,5 +1,5 @@
--- ---
title: Repos title: Repositories
--- ---
```js ```js
@@ -115,7 +115,7 @@ const doiFullCount = repoRows.filter(r => r._doiTier === "full").length;
const doiNoneCount = repoRows.filter(r => r._doiTier === "none").length; const doiNoneCount = repoRows.filter(r => r._doiTier === "none").length;
``` ```
# Repos # Repositories
```js ```js
import {withDocHelp} from "./components/doc-overlay.js"; import {withDocHelp} from "./components/doc-overlay.js";