BatchCheck makes parallelized check requests for tuples. The check results are returned as slice, where the result index matches the tuple index of the incoming tuples array.
(ctx context.Context, tuples []*ketoapi.RelationTuple, maxDepth int)
| 270 | // BatchCheck makes parallelized check requests for tuples. The check results are returned as slice, where the |
| 271 | // result index matches the tuple index of the incoming tuples array. |
| 272 | func (e *Engine) BatchCheck(ctx context.Context, |
| 273 | tuples []*ketoapi.RelationTuple, |
| 274 | maxDepth int) ([]checkgroup.Result, error) { |
| 275 | |
| 276 | eg := &errgroup.Group{} |
| 277 | eg.SetLimit(e.d.Config(ctx).BatchCheckParallelizationLimit()) |
| 278 | |
| 279 | mapper := e.d.ReadOnlyMapper() |
| 280 | results := make([]checkgroup.Result, len(tuples)) |
| 281 | for i, tuple := range tuples { |
| 282 | i := i |
| 283 | tuple := tuple |
| 284 | eg.Go(func() error { |
| 285 | internalTuple, err := mapper.FromTuple(ctx, tuple) |
| 286 | if err != nil { |
| 287 | results[i] = checkgroup.Result{ |
| 288 | Membership: checkgroup.MembershipUnknown, |
| 289 | Err: err, |
| 290 | } |
| 291 | } else { |
| 292 | results[i] = e.CheckRelationTuple(ctx, internalTuple[0], maxDepth) |
| 293 | } |
| 294 | return nil |
| 295 | }) |
| 296 | } |
| 297 | |
| 298 | if err := eg.Wait(); err != nil { |
| 299 | return nil, err |
| 300 | } |
| 301 | |
| 302 | return results, nil |
| 303 | } |