MCPcopy
hub / github.com/cayleygraph/cayley / loadIteratorToDepth

Method loadIteratorToDepth

schema/loader.go:414–543  ·  view source on GitHub ↗
(ctx context.Context, dst reflect.Value, depth int, list graph.Iterator)

Source from the content-addressed store, hash-verified

412}
413
414func (l *loader) loadIteratorToDepth(ctx context.Context, dst reflect.Value, depth int, list graph.Iterator) error {
415 if ctx == nil {
416 ctx = context.TODO()
417 }
418 if dst.Kind() == reflect.Ptr {
419 dst = dst.Elem()
420 }
421 et := dst.Type()
422 slice, chanl := false, false
423 if dst.Kind() == reflect.Slice {
424 et = et.Elem()
425 slice = true
426 } else if dst.Kind() == reflect.Chan {
427 et = et.Elem()
428 chanl = true
429 defer dst.Close()
430 }
431 fields, err := l.c.rulesFor(et)
432 if err != nil {
433 return err
434 }
435
436 ctxDone := func() bool {
437 select {
438 case <-ctx.Done():
439 return true
440 default:
441 }
442 return false
443 }
444
445 if ctxDone() {
446 return ctx.Err()
447 }
448
449 rootOnly := depth == 0
450 it, err := l.iteratorForType(list, et, rootOnly)
451 if err != nil {
452 return err
453 }
454 defer it.Close()
455
456 ctx = context.WithValue(ctx, fieldsCtxKey{}, fields)
457 for it.Next(ctx) {
458 if ctxDone() {
459 return ctx.Err()
460 }
461 id := l.qs.NameOf(it.Result())
462 if id != nil {
463 if sv, ok := l.seen[id]; ok {
464 if slice {
465 dst.Set(reflect.Append(dst, sv.Elem()))
466 } else if chanl {
467 dst.Send(sv.Elem())
468 } else if dst.Kind() != reflect.Ptr {
469 dst.Set(sv.Elem())
470 return nil
471 } else {

Callers 2

loadToValueMethod · 0.95
LoadIteratorToDepthMethod · 0.80

Calls 15

iteratorForTypeMethod · 0.95
loadToValueMethod · 0.95
NewAndFunction · 0.92
mergeMapFunction · 0.85
rulesForMethod · 0.80
SendMethod · 0.80
CloseMethod · 0.65
ErrMethod · 0.65
NextMethod · 0.65
NameOfMethod · 0.65
ResultMethod · 0.65
TagResultsMethod · 0.65

Tested by

no test coverage detected