[Lens] Reduce call stack for formula (#171744)

## Summary

Reduce a bit the call stack with associated perf speedup in a scenario
with many fields.

*Note*: initially I've optimize somehow the memoization of
`getAvailableOperationsByMetadata` but it was too brittle as changing
something in the dataview leads to wrong results. I'm not sure this
could actually happen in real life ™️ but a test hijacking a bit a
dataView found that out.
This commit is contained in:
Marco Liberati 2023-11-30 14:32:07 +01:00 committed by GitHub
parent 62d0ce4c7c
commit 545e472d8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -215,18 +215,18 @@ export function getPossibleFunctions(
operationDefinitionMap?: Record<string, GenericOperationDefinition>
) {
const available = memoizedGetAvailableOperationsByMetadata(indexPattern, operationDefinitionMap);
const possibleOperationNames: string[] = [];
available.forEach((a) => {
const possibleOperationNames: Set<string> = new Set();
for (const a of available) {
if (a.operationMetaData.dataType === 'number' && !a.operationMetaData.isBucketed) {
possibleOperationNames.push(
...a.operations
.filter((o) => o.type !== 'managedReference' || o.usedInMath)
.map((o) => o.operationType)
);
for (const o of a.operations) {
if (o.type !== 'managedReference' || o.usedInMath) {
possibleOperationNames.add(o.operationType);
}
}
}
});
}
return [...uniq(possibleOperationNames), ...Object.keys(tinymathFunctions)];
return Array.from(possibleOperationNames.keys()).concat(Object.keys(tinymathFunctions));
}
function getFunctionSuggestions(
@ -261,7 +261,7 @@ function getArgumentSuggestions(
if (tinymathFunction) {
if (tinymathFunction.positionalArguments[position]) {
return {
list: uniq(getPossibleFunctions(indexPattern, operationDefinitionMap)).map((f) => ({
list: getPossibleFunctions(indexPattern, operationDefinitionMap).map((f) => ({
type: 'math' as const,
label: f,
})),