Skip to content

Commit

Permalink
cache classMappingById calls (finos#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-rpant1729 authored Oct 9, 2024
1 parent f2da6cc commit dd09f84
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ function meta::pure::graphFetch::routing::routeRootGraphFetchTree(root: RootGrap
])
);

$routedTree->ensureXStoreRequirementsAtCurrentLevel($rootGetAllExpression, [], [], $mapping, $extensions)->splitPropertyTrees($mapping, $extensions, $exeCtx)->cast(@RoutedRootGraphFetchTree<Any>);
let idToClassMapping = buildClassMappingsById($mapping);
$routedTree->ensureXStoreRequirementsAtCurrentLevel($rootGetAllExpression, [], [], $mapping, $extensions)->splitPropertyTrees($mapping, $idToClassMapping, $extensions, $exeCtx)->cast(@RoutedRootGraphFetchTree<Any>);
}

function meta::pure::graphFetch::splitPropertyTrees(tree:RoutedGraphFetchTree[1], mapping: Mapping[1], extensions:meta::pure::extension::Extension[*], exeCtx: meta::pure::runtime::ExecutionContext[1]):RoutedGraphFetchTree[1]
function meta::pure::graphFetch::splitPropertyTrees(tree:RoutedGraphFetchTree[1], mapping: Mapping[1], idToClassMapping:Map<String, List<SetImplementation>>[1], extensions:meta::pure::extension::Extension[*], exeCtx: meta::pure::runtime::ExecutionContext[1]):RoutedGraphFetchTree[1]
{
let updatedSubTrees = $tree.subTrees->map(st | let propertyTree = $st->cast(@RoutedPropertyGraphFetchTree);
let splitPropertyTreeWhenMultipleSetImpls = ($propertyTree.sets->size() > 1) && ($propertyTree.sets->forAll(set | $set->storeContractForSetImplementation($mapping, $extensions).first.splitGraphFetchTreeForPropertyUnion));
Expand All @@ -252,17 +253,17 @@ function meta::pure::graphFetch::splitPropertyTrees(tree:RoutedGraphFetchTree[1]
let sourceSetImplementation = $tree.sets->toOne();
let multipleExpressionForUnion = meta::pure::graphFetch::getMultiValueSpecBasedOnSetImplPermutation($property.expressionSequence->evaluateAndDeactivate()->toOne()->cast(@StoreMappingRoutedValueSpecification), $sourceSetImplementation, $exeCtx, $extensions);
$multipleExpressionForUnion->map(x | ^$propertyTree(property = ^$property(expressionSequence = $x), sets = $x.sets););,
| let sourceSetImplementationIds = $mapping->allSuperSetImplementationIds($tree.sets->toOne().id);
| let sourceSetImplementationIds = $idToClassMapping->allSuperSetImplementationIds($tree.sets->toOne().id);
$propertyTree.propertyMapping->filter(x | $x.sourceSetImplementationId->in($sourceSetImplementationIds))->map(pm | ^$propertyTree(propertyMapping = $pm, sets = $propertyTree.sets->filter(s | $s.id == $pm.targetSetImplementationId)));
);,
| if($splitPropertyTreeWhenMultiplePropertyMappings,
| let sourceSetImplementationIds = $mapping->allSuperSetImplementationIds($tree.sets->toOne().id);
| let sourceSetImplementationIds = $idToClassMapping->allSuperSetImplementationIds($tree.sets->toOne().id);
^$propertyTree(propertyMapping = $propertyTree.propertyMapping->filter(pm | $pm.sourceSetImplementationId->in($sourceSetImplementationIds)));,
| $propertyTree
);
);
);
^$tree(subTrees = $updatedSubTrees->map(s | $s->cast(@RoutedGraphFetchTree)->splitPropertyTrees($mapping, $extensions, $exeCtx)));
^$tree(subTrees = $updatedSubTrees->map(s | $s->cast(@RoutedGraphFetchTree)->splitPropertyTrees($mapping, $idToClassMapping, $extensions, $exeCtx)));
}

function meta::pure::graphFetch::getMultiValueSpecBasedOnSetImplPermutation(routedVs: StoreMappingRoutedValueSpecification[1], sourceSetImplementation:SetImplementation[1], exeCtx: meta::pure::runtime::ExecutionContext[1], extensions:meta::pure::extension::Extension[*]): StoreMappingRoutedValueSpecification[*]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ function meta::pure::mapping::buildClassMappingsByClassMap(mapping:Mapping[1]):M
$mappingsInScope->meta::pure::router::routing::potentiallyResolveOperation($mapping, $allClassMappings)->groupBy(i | $i.class);
}

function meta::pure::mapping::buildClassMappingsById(mapping:Mapping[1]):Map<String,List<SetImplementation>>[1]
{
$mapping->classMappings()->groupBy(m|$m.id);
}

function meta::pure::mapping::getClassMappingById(idToClassMapping: Map<String,List<SetImplementation>>[1], id: String[1]): SetImplementation[*]
{
$idToClassMapping->get($id).values;
}

function meta::pure::mapping::mergeMappings(mappings: Mapping[1..*]):Mapping[1]
{
if($mappings->distinct()->size()==1,
Expand Down Expand Up @@ -227,6 +237,14 @@ function meta::pure::router::routing::findMappingsFromProperty(p:AbstractPropert
);
}

function meta::pure::router::routing::allSuperSetImplementationIds(idToClassMapping:Map<String, List<SetImplementation>>[1], id:String[1]):String[*]
{
let setImplementation = getClassMappingById($idToClassMapping, $id);
$id->concatenate(if ($setImplementation->isEmpty() || $setImplementation.superSetImplementationId->isEmpty(),
| [],
| $idToClassMapping->allSuperSetImplementationIds($setImplementation.superSetImplementationId->toOne())));
}

function meta::pure::router::routing::inlineEmbeddedMapping(i:InlineEmbeddedSetImplementation[1], m:Mapping[1]):EmbeddedSetImplementation[1]
{
let cm = $m->classMappingById($i.inlineSetImplementationId);
Expand Down
Loading

0 comments on commit dd09f84

Please sign in to comment.