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

Method loadOwner

pkg/database/ent/meta_query.go:404–432  ·  view source on GitHub ↗
(ctx context.Context, query *AlertQuery, nodes []*Meta, init func(*Meta), assign func(*Meta, *Alert))

Source from the content-addressed store, hash-verified

402}
403
404func (_q *MetaQuery) loadOwner(ctx context.Context, query *AlertQuery, nodes []*Meta, init func(*Meta), assign func(*Meta, *Alert)) error {
405 ids := make([]int, 0, len(nodes))
406 nodeids := make(map[int][]*Meta)
407 for i := range nodes {
408 fk := nodes[i].AlertMetas
409 if _, ok := nodeids[fk]; !ok {
410 ids = append(ids, fk)
411 }
412 nodeids[fk] = append(nodeids[fk], nodes[i])
413 }
414 if len(ids) == 0 {
415 return nil
416 }
417 query.Where(alert.IDIn(ids...))
418 neighbors, err := query.All(ctx)
419 if err != nil {
420 return err
421 }
422 for _, n := range neighbors {
423 nodes, ok := nodeids[n.ID]
424 if !ok {
425 return fmt.Errorf(`unexpected foreign-key "alert_metas" returned %v`, n.ID)
426 }
427 for i := range nodes {
428 assign(nodes[i], n)
429 }
430 }
431 return nil
432}
433
434func (_q *MetaQuery) sqlCount(ctx context.Context) (int, error) {
435 _spec := _q.querySpec()

Callers 1

sqlAllMethod · 0.95

Calls 3

IDInFunction · 0.92
WhereMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected