MCPcopy
hub / github.com/openfga/openfga / buildRecursiveMapper

Function buildRecursiveMapper

internal/graph/recursive_resolver.go:164–201  ·  view source on GitHub ↗
(ctx context.Context, req *ResolveCheckRequest, mapping *recursiveMapping)

Source from the content-addressed store, hash-verified

162}
163
164func buildRecursiveMapper(ctx context.Context, req *ResolveCheckRequest, mapping *recursiveMapping) (storage.TupleMapper, error) {
165 var iter storage.TupleIterator
166 var err error
167 typesys, _ := typesystem.TypesystemFromContext(ctx)
168 ds, _ := storage.RelationshipTupleReaderFromContext(ctx)
169 consistencyOpts := storage.ConsistencyOptions{
170 Preference: req.GetConsistency(),
171 }
172
173 switch mapping.kind {
174 case storage.UsersetKind:
175 objectType := req.GetTupleKey().GetObject()
176 relation := req.GetTupleKey().GetRelation()
177 iter, err = ds.ReadUsersetTuples(ctx, req.GetStoreID(), storage.ReadUsersetTuplesFilter{
178 Object: objectType,
179 Relation: relation,
180 AllowedUserTypeRestrictions: mapping.allowedUserTypeRestrictions,
181 }, storage.ReadUsersetTuplesOptions{Consistency: consistencyOpts})
182 case storage.TTUKind:
183 objectType := req.GetTupleKey().GetObject()
184 iter, err = ds.Read(ctx, req.GetStoreID(),
185 storage.ReadFilter{Object: objectType, Relation: mapping.tuplesetRelation, User: ""},
186 storage.ReadOptions{Consistency: consistencyOpts})
187 default:
188 return nil, errors.New("unsupported mapper kind")
189 }
190 if err != nil {
191 return nil, err
192 }
193 filteredIter := storage.NewConditionsFilteredTupleKeyIterator(
194 storage.NewFilteredTupleKeyIterator(
195 storage.NewTupleKeyIteratorFromTupleIterator(iter),
196 validation.FilterInvalidTuples(typesys),
197 ),
198 checkutil.BuildTupleKeyConditionFilter(ctx, req.GetContext(), typesys),
199 )
200 return storage.WrapIterator(mapping.kind, filteredIter), nil
201}
202
203func (c *LocalChecker) recursiveMatchUserUserset(ctx context.Context, req *ResolveCheckRequest, mapping *recursiveMapping, currentLevelFromObject *hashset.Set, usersetFromUser *hashset.Set) (*ResolveCheckResponse, error) {
204 ctx, span := tracer.Start(ctx, "recursiveMatchUserUserset", trace.WithAttributes(

Calls 15

TypesystemFromContextFunction · 0.92
FilterInvalidTuplesFunction · 0.92
WrapIteratorFunction · 0.92
GetConsistencyMethod · 0.65
GetObjectMethod · 0.65
GetTupleKeyMethod · 0.65
GetRelationMethod · 0.65

Tested by 2

TestBuildRecursiveMapperFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…