diff --git a/ai-compliance-sdk/internal/api/handlers/iace_handler.go b/ai-compliance-sdk/internal/api/handlers/iace_handler.go index 553b36a..c718ab3 100644 --- a/ai-compliance-sdk/internal/api/handlers/iace_handler.go +++ b/ai-compliance-sdk/internal/api/handlers/iace_handler.go @@ -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)