MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / loadDecisions

Method loadDecisions

pkg/database/ent/alert_query.go:577–606  ·  view source on GitHub ↗
(ctx context.Context, query *DecisionQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Decision))

Source from the content-addressed store, hash-verified

575 return nil
576}
577func (_q *AlertQuery) loadDecisions(ctx context.Context, query *DecisionQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Decision)) error {
578 fks := make([]driver.Value, 0, len(nodes))
579 nodeids := make(map[int]*Alert)
580 for i := range nodes {
581 fks = append(fks, nodes[i].ID)
582 nodeids[nodes[i].ID] = nodes[i]
583 if init != nil {
584 init(nodes[i])
585 }
586 }
587 if len(query.ctx.Fields) > 0 {
588 query.ctx.AppendFieldOnce(decision.FieldAlertDecisions)
589 }
590 query.Where(predicate.Decision(func(s *sql.Selector) {
591 s.Where(sql.InValues(s.C(alert.DecisionsColumn), fks...))
592 }))
593 neighbors, err := query.All(ctx)
594 if err != nil {
595 return err
596 }
597 for _, n := range neighbors {
598 fk := n.AlertDecisions
599 node, ok := nodeids[fk]
600 if !ok {
601 return fmt.Errorf(`unexpected referenced foreign-key "alert_decisions" returned %v for node %v`, fk, n.ID)
602 }
603 assign(node, n)
604 }
605 return nil
606}
607func (_q *AlertQuery) loadEvents(ctx context.Context, query *EventQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Event)) error {
608 fks := make([]driver.Value, 0, len(nodes))
609 nodeids := make(map[int]*Alert)

Callers 1

sqlAllMethod · 0.95

Calls 4

WhereMethod · 0.95
DecisionFuncType · 0.92
initFunction · 0.70
AllMethod · 0.45

Tested by

no test coverage detected