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)
|
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 allAssessments []iace.RiskAssessment
|
||||||
var allMitigations []iace.Mitigation
|
for _, a := range assessmentMap {
|
||||||
for _, hazard := range hazards {
|
allAssessments = append(allAssessments, a)
|
||||||
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...)
|
|
||||||
}
|
}
|
||||||
|
allMitigations, _ := h.store.ListMitigationsByProject(c.Request.Context(), projectID)
|
||||||
|
|
||||||
evidence, _ := h.store.ListEvidence(c.Request.Context(), projectID)
|
evidence, _ := h.store.ListEvidence(c.Request.Context(), projectID)
|
||||||
techFileSections, _ := h.store.ListTechFileSections(c.Request.Context(), projectID)
|
techFileSections, _ := h.store.ListTechFileSections(c.Request.Context(), projectID)
|
||||||
|
|||||||
Reference in New Issue
Block a user