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

Method loadOwner

pkg/database/ent/alert_query.go:545–576  ·  view source on GitHub ↗
(ctx context.Context, query *MachineQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Machine))

Source from the content-addressed store, hash-verified

543}
544
545func (_q *AlertQuery) loadOwner(ctx context.Context, query *MachineQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Machine)) error {
546 ids := make([]int, 0, len(nodes))
547 nodeids := make(map[int][]*Alert)
548 for i := range nodes {
549 if nodes[i].machine_alerts == nil {
550 continue
551 }
552 fk := *nodes[i].machine_alerts
553 if _, ok := nodeids[fk]; !ok {
554 ids = append(ids, fk)
555 }
556 nodeids[fk] = append(nodeids[fk], nodes[i])
557 }
558 if len(ids) == 0 {
559 return nil
560 }
561 query.Where(machine.IDIn(ids...))
562 neighbors, err := query.All(ctx)
563 if err != nil {
564 return err
565 }
566 for _, n := range neighbors {
567 nodes, ok := nodeids[n.ID]
568 if !ok {
569 return fmt.Errorf(`unexpected foreign-key "machine_alerts" returned %v`, n.ID)
570 }
571 for i := range nodes {
572 assign(nodes[i], n)
573 }
574 }
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)

Callers 1

sqlAllMethod · 0.95

Calls 3

IDInFunction · 0.92
WhereMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected