resolveRemotes fetches remote data for the marked insertion points
(
ctx context.Context,
from []jsn.Field,
sfmap map[string]*qcode.Select,
cursorFields map[string]struct{},
)
| 56 | |
| 57 | // resolveRemotes fetches remote data for the marked insertion points |
| 58 | func (s *gstate) resolveRemotes( |
| 59 | ctx context.Context, |
| 60 | from []jsn.Field, |
| 61 | sfmap map[string]*qcode.Select, |
| 62 | cursorFields map[string]struct{}, |
| 63 | ) ([]jsn.Field, map[string]json.RawMessage, error) { |
| 64 | selects := s.cs.st.qc.Selects |
| 65 | |
| 66 | // replacement data for the marked insertion points |
| 67 | // key and value will be replaced by whats below |
| 68 | to := make([]jsn.Field, len(from)) |
| 69 | extra := make(map[string]json.RawMessage) |
| 70 | var extraMutex sync.Mutex |
| 71 | |
| 72 | var wg sync.WaitGroup |
| 73 | wg.Add(len(from)) |
| 74 | |
| 75 | var cerr error |
| 76 | var cerrMutex sync.Mutex |
| 77 | |
| 78 | for i, id := range from { |
| 79 | // use the json key to find the related Select object |
| 80 | sel, ok := sfmap[string(id.Key)] |
| 81 | if !ok { |
| 82 | return nil, nil, fmt.Errorf("invalid remote field key") |
| 83 | } |
| 84 | |
| 85 | // Lookup the resolver. Top-level remotes (ParentID == -1) are |
| 86 | // keyed by table name alone; row-joins are keyed by table+parent. |
| 87 | var ( |
| 88 | r resItem |
| 89 | rid []byte |
| 90 | rkey string |
| 91 | ) |
| 92 | if sel.ParentID == -1 { |
| 93 | rkey = sel.Table |
| 94 | r, ok = s.gj.rmap[rkey] |
| 95 | } else { |
| 96 | p := selects[sel.ParentID] |
| 97 | rkey = sel.Table + p.Table |
| 98 | r, ok = s.gj.rmap[rkey] |
| 99 | if ok { |
| 100 | rid = jsn.Value(id.Value) |
| 101 | if len(rid) == 0 { |
| 102 | return nil, nil, fmt.Errorf("invalid remote field id") |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | if !ok { |
| 107 | return nil, nil, fmt.Errorf("no resolver found for remote %q", rkey) |
| 108 | } |
| 109 | |
| 110 | go func(n int, id []byte, sel *qcode.Select, r resItem, rkey string) { |
| 111 | defer wg.Done() |
| 112 | |
| 113 | ctx1, span := s.gj.spanStart(ctx, "Execute Remote Request") |
| 114 | defer span.End() |
| 115 |
no test coverage detected