[AAP-103746] perf(api): optimize health check, viewset queries, and API root pattern lookup #554
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 484 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.370
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #554"
general
weight: 0.35
redhat-chai-bot
Description
-
apps/core/views/health.py: uses.only("status", "modified")when fetching the latestAnonymizedMetricsPayloadinHealthView.get()so theanonymized_dataJSONB blob is not transferred or deserialized on health probes.-
apps/tasks/v1/views.py&apps/tasks/v1/serializers.py: annotates_executions_count=Count("executions")onTaskViewSetactions serialized byTaskSerializer(with.order_by("id")preservingTask.Meta.orderingonpending/runningand a live-count fallback for standalone serializer callers), and uses.only("id", "name", "status", "completed_at")on the dry-runcleanuppreview.-
apps/core/v1/viewsets/organization.py&apps/core/v1/viewsets/team.py: addsselect_related("created_by", "modified_by", "resource")(and"organization"onTeamViewSet) to eliminate per-row queries when serializingsummary_fields.-
apps/core/views/api_root.py: caches extracted(clean_path, pattern_name)tuples perURLResolverinstance in aWeakKeyDictionary.- Adds unit tests guarding SQL column exclusion, constant query counts, ordering preservation, and resolver-scoped caching.
-
/health/probes were fetching multi-MBanonymized_dataJSONB blobs on every probe, list endpoints were issuing O(N) queries per page, andAPIRootViewwas recursively runningsimplify_regex()over the full URL tree on every request.- Avoids fetching unused JSONB blobs, collapses O(N) viewset queries into O(1) joined/annotated queries, and caches immutable URL pattern extraction per resolver. In paired benchmarks on a containerized reference deployment (RHEL 9.6, Python 3.12, Django 5.2, PostgreSQL 15, identical SHA-256 response digests):
-
/health/: 4.73× faster (3.681s → 0.779sfor 100 reqs),-13.0 MiBpeak RSS- ViewSet endpoints: 2.83× faster (
3.738s → 1.319s; queries27→2tasks,19→1pending,55→6orgs,81→6teams)-
APIRootView(/api/v1/): 3.17× faster (1.215s → 0.383sfor 500 reqs)Type of Change
Self-Review Checklist
Testing Instructions
Prerequisites
make composeor local test DB)Steps to Test
1. Run lint and format checks:
2. Run the targeted test suites:
Expected Results
anonymized_datais excluded from/health/SQL, constant query counts and preserved ordering across task/org/team endpoints, and single-extraction caching per resolver inAPIRootView.