perf: Fix N+1 query in production line dashboard (27s → <1s)
Build + Deploy / build-admin-compliance (push) Successful in 2m20s
Build + Deploy / build-backend-compliance (push) Successful in 3m24s
Build + Deploy / build-ai-sdk (push) Successful in 57s
Build + Deploy / build-developer-portal (push) Successful in 1m21s
Build + Deploy / build-tts (push) Successful in 1m38s
Build + Deploy / build-document-crawler (push) Successful in 40s
Build + Deploy / build-dsms-gateway (push) Successful in 26s
Build + Deploy / build-dsms-node (push) Successful in 11s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-python-backend (push) Successful in 52s
CI / test-python-document-crawler (push) Successful in 38s
CI / test-python-dsms-gateway (push) Successful in 25s
CI / validate-canonical-controls (push) Successful in 16s
Build + Deploy / trigger-orca (push) Successful in 3m56s
CI / loc-budget (push) Failing after 23s
CI / secret-scan (push) Has been skipped
CI / go-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m28s
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / test-go (push) Failing after 52s
Build + Deploy / build-admin-compliance (push) Successful in 2m20s
Build + Deploy / build-backend-compliance (push) Successful in 3m24s
Build + Deploy / build-ai-sdk (push) Successful in 57s
Build + Deploy / build-developer-portal (push) Successful in 1m21s
Build + Deploy / build-tts (push) Successful in 1m38s
Build + Deploy / build-document-crawler (push) Successful in 40s
Build + Deploy / build-dsms-gateway (push) Successful in 26s
Build + Deploy / build-dsms-node (push) Successful in 11s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-python-backend (push) Successful in 52s
CI / test-python-document-crawler (push) Successful in 38s
CI / test-python-dsms-gateway (push) Successful in 25s
CI / validate-canonical-controls (push) Successful in 16s
Build + Deploy / trigger-orca (push) Successful in 3m56s
CI / loc-budget (push) Failing after 23s
CI / secret-scan (push) Has been skipped
CI / go-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m28s
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / test-go (push) Failing after 52s
GetLineDashboard called GetLatestAssessment per hazard (N+1 queries). Replaced with GetLatestAssessmentsByProject — one batch query per station instead of one per hazard. With 50+ hazards across multiple stations, this reduces hundreds of DB queries to ~5. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -256,10 +256,12 @@ func (s *Store) buildStationDashboard(ctx context.Context, st ProductionLineStat
|
|||||||
mitigations, _ := s.ListMitigationsByProject(ctx, st.ProjectID)
|
mitigations, _ := s.ListMitigationsByProject(ctx, st.ProjectID)
|
||||||
sd.MitigationCount = len(mitigations)
|
sd.MitigationCount = len(mitigations)
|
||||||
|
|
||||||
// Compute risk summary and max SIL/PL from latest assessments
|
// Batch-load all latest assessments in ONE query (not N+1)
|
||||||
|
latestByHazard, _ := s.GetLatestAssessmentsByProject(ctx, st.ProjectID)
|
||||||
|
|
||||||
for _, h := range hazards {
|
for _, h := range hazards {
|
||||||
latest, _ := s.GetLatestAssessment(ctx, h.ID)
|
latest, ok := latestByHazard[h.ID]
|
||||||
if latest == nil {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user