perf: N+1 Fix in GetProject/buildCompletenessContext
462 einzelne Queries (Assessments + Mitigations pro Hazard) durch 2 Batch-Queries ersetzt. GetProject von ~22s auf <1s. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -82,15 +82,13 @@ func (h *IACEHandler) buildCompletenessContext(
|
||||
|
||||
hazards, _ := h.store.ListHazards(c.Request.Context(), projectID)
|
||||
|
||||
// Batch queries instead of N+1 per hazard (was 462 queries for 231 hazards)
|
||||
assessmentMap, _ := h.store.GetLatestAssessmentsByProject(c.Request.Context(), projectID)
|
||||
var allAssessments []iace.RiskAssessment
|
||||
var allMitigations []iace.Mitigation
|
||||
for _, hazard := range hazards {
|
||||
assessments, _ := h.store.ListAssessments(c.Request.Context(), hazard.ID)
|
||||
allAssessments = append(allAssessments, assessments...)
|
||||
|
||||
mitigations, _ := h.store.ListMitigations(c.Request.Context(), hazard.ID)
|
||||
allMitigations = append(allMitigations, mitigations...)
|
||||
for _, a := range assessmentMap {
|
||||
allAssessments = append(allAssessments, a)
|
||||
}
|
||||
allMitigations, _ := h.store.ListMitigationsByProject(c.Request.Context(), projectID)
|
||||
|
||||
evidence, _ := h.store.ListEvidence(c.Request.Context(), projectID)
|
||||
techFileSections, _ := h.store.ListTechFileSections(c.Request.Context(), projectID)
|
||||
|
||||
Reference in New Issue
Block a user