Skip to content

Commit

Permalink
⚡ Improve getOperationSupportMatrix performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Nov 6, 2020
1 parent f586105 commit c2bd377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix

filteredOperationsByMetadata.forEach(({ operations }) => {
operations.forEach((operation) => {
// replace spread operator by regular push as it's performance wise faster
if (operation.type === 'field') {
supportedOperationsByField[operation.field] = [
...(supportedOperationsByField[operation.field] ?? []),
operation.operationType,
];

supportedFieldsByOperation[operation.operationType] = [
...(supportedFieldsByOperation[operation.operationType] ?? []),
operation.field,
];
if (!supportedOperationsByField[operation.field]) {
supportedOperationsByField[operation.field] = [];
}
supportedOperationsByField[operation.field]?.push(operation.operationType);

if (!supportedFieldsByOperation[operation.operationType]) {
supportedFieldsByOperation[operation.operationType] = [];
}
supportedFieldsByOperation[operation.operationType]?.push(operation.field);
} else if (operation.type === 'none') {
supportedOperationsWithoutField.push(operation.operationType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ export function getAvailableOperationsByMetadata(indexPattern: IndexPattern) {

operationDefinitions.sort(getSortScoreByPriority).forEach((operationDefinition) => {
if (operationDefinition.input === 'field') {
indexPattern.fields.forEach((field) => {
addToMap(
return indexPattern.fields.forEach((field) => {
return addToMap(
{
type: 'field',
operationType: operationDefinition.type,
Expand All @@ -156,8 +156,9 @@ export function getAvailableOperationsByMetadata(indexPattern: IndexPattern) {
operationDefinition.getPossibleOperationForField(field)
);
});
} else if (operationDefinition.input === 'none') {
addToMap(
}
if (operationDefinition.input === 'none') {
return addToMap(
{
type: 'none',
operationType: operationDefinition.type,
Expand Down

0 comments on commit c2bd377

Please sign in to comment.