Skip to content

Commit

Permalink
fix(designer): Performance improvement by removing spread accumulator…
Browse files Browse the repository at this point in the history
…s in the code (#4619)

* fix(designer): Performance improvement by removing spread accumulators in the code

* forgot to save a file

* fix tests
  • Loading branch information
hartra344 committed Apr 16, 2024
1 parent c555d59 commit 3c8128c
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 155 deletions.
2 changes: 2 additions & 0 deletions Localize/lang/strings.json
Expand Up @@ -1902,6 +1902,7 @@
"_dwrqEc.comment": "Warnings section title",
"_e+GuGo.comment": "Placeholder title for a newly inserted Text parameter",
"_e00zot.comment": "Recurrence parameter group title",
"_e1gQAz.comment": "Debug logic app project error text",
"_e4JZEY.comment": "Time zone value ",
"_e9OvzW.comment": "Clear",
"_e9bIKh.comment": "Message on failed generation",
Expand Down Expand Up @@ -2533,6 +2534,7 @@
"dwrqEc": "Warnings",
"e+GuGo": "Input",
"e00zot": "How often do you want to check for items?",
"e1gQAz": "Please start the project by pressing F5 or run it through the Run and Debug view",
"e4JZEY": "(UTC+07:00) Tomsk",
"e9OvzW": "Clear",
"e9bIKh": "Failed to generate XSLT.",
Expand Down
Expand Up @@ -67,7 +67,7 @@ export const DesignerCommandBar = ({
ignoreNonCriticalErrors: true,
});

const validationErrorsList = Object.entries(designerState.operations.inputParameters).reduce((acc, [id, nodeInputs]) => {
const validationErrorsList = Object.entries(designerState.operations.inputParameters).reduce((acc: any, [id, nodeInputs]) => {
const hasValidationErrors = Object.values(nodeInputs.parameterGroups).some((parameterGroup) => {
return parameterGroup.parameters.some((parameter) => {
const validationErrors = validateParameter(parameter, parameter.value);
Expand All @@ -84,7 +84,10 @@ export const DesignerCommandBar = ({
return validationErrors.length;
});
});
return hasValidationErrors ? { ...acc, [id]: hasValidationErrors } : { ...acc };
if (hasValidationErrors) {
acc[id] = hasValidationErrors;
}
return acc;
}, {});

const hasParametersErrors = !isNullOrEmpty(validationErrorsList);
Expand Down
Expand Up @@ -81,13 +81,13 @@ const traverseDefinition = (operation: any, callback: (operation: any) => void)
...(operation?.actions ?? {}),
...(operation?.else?.actions ?? {}),
...(operation?.default?.actions ?? {}),
...(Object.values(operation?.cases ?? {}).reduce(
(acc: any, curr: any) => ({
...(Object.values(operation?.cases ?? {}).reduce((acc: any, curr: any) => {
return {
// biome-ignore lint/performance/noAccumulatingSpread: There are probably better ways to do this but this is a more complex one to fix
...acc,
...curr.actions,
}),
{}
) as any),
};
}, {}) as any),
};

Object.values(children).forEach((child: any) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/vs-code-designer/src/app/utils/codeless/connection.ts
Expand Up @@ -260,7 +260,8 @@ export function resolveSettingsInConnection(
value = settings[settingKey];
}

return { ...result, [parameterKey]: value };
result[parameterKey] = value;
return result;
}, {}),
}
: connectionInfo;
Expand Down
Expand Up @@ -4,7 +4,8 @@ import type { IDropdownOption } from '@fluentui/react';

export const parseResourceGroups = (workflowItems: Array<WorkflowsList>): IDropdownOption[] => {
const resourceGroups: Array<string> = workflowItems.reduce((acc: Array<string>, curr: WorkflowsList): Array<string> => {
return [...acc, curr?.resourceGroup];
acc.push(curr.resourceGroup);
return acc;
}, []);

const dropdownGroups: IDropdownOption[] = [...new Set(resourceGroups)].map((resourceGroup) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/vs-code-react/src/app/overview/app.tsx
Expand Up @@ -75,7 +75,7 @@ export const OverviewApp = () => {
const runItems = useMemo(
() =>
data?.pages?.reduce<RunDisplayItem[]>((acc, val) => {
return [...acc, ...val.runs.map(mapToRunItem)];
return acc.concat(val.runs.map(mapToRunItem));
}, []),
[data?.pages]
);
Expand Down
3 changes: 1 addition & 2 deletions biome.json
Expand Up @@ -26,8 +26,7 @@
"recommended": false,
"performance": {
"all": true,
"noDelete": "off",
"noAccumulatingSpread": "off"
"noDelete": "off"
},
"a11y": {
"all": false
Expand Down
Expand Up @@ -105,7 +105,8 @@ export function serialize(models: DynamicallyAddedParameterInputsModel[], isRequ
.reduce((resultPropertiesObj, nextProperty) => {
// Convert array to object; replace array index key with schemaKey
const [schemaKey, propertyValue] = Object.entries(nextProperty)[0];
return { ...resultPropertiesObj, [schemaKey]: propertyValue };
resultPropertiesObj[schemaKey] = propertyValue;
return resultPropertiesObj;
}, {});

let rootObject: OpenApiSchema;
Expand Down
28 changes: 12 additions & 16 deletions libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts
Expand Up @@ -2,25 +2,21 @@ import { encodeStringSegmentTokensInDomContext } from '../../../../editor/base/u
import type { ValueSegment } from '@microsoft/logic-apps-shared';
import DomPurify from 'dompurify';

const encodeReduceFunction = (acc: Record<string, string>, key: string) => {
acc[key] = encodeURIComponent(key);
return acc;
};
const decodeReduceFunction = (acc: Record<string, string>, key: string) => {
acc[encodeURIComponent(key)] = key;
return acc;
}
const htmlUnsafeCharacters = ['<', '>'];
const htmlUnsafeCharacterEncodingMap: Record<string, string> = htmlUnsafeCharacters.reduce(
(acc, key) => ({ ...acc, [key]: encodeURIComponent(key) }),
{}
);
const htmlUnsafeCharacterDecodingMap: Record<string, string> = htmlUnsafeCharacters.reduce(
(acc, key) => ({ ...acc, [encodeURIComponent(key)]: key }),
{}
);
const htmlUnsafeCharacterEncodingMap: Record<string, string> = htmlUnsafeCharacters.reduce(encodeReduceFunction, {});
const htmlUnsafeCharacterDecodingMap: Record<string, string> = htmlUnsafeCharacters.reduce(decodeReduceFunction, {});

const lexicalUnsafeCharacters = ['&', '"'];
const lexicalUnsafeCharacterEncodingMap: Record<string, string> = lexicalUnsafeCharacters.reduce(
(acc, key) => ({ ...acc, [key]: encodeURIComponent(key) }),
{}
);
const lexicalUnsafeCharacterDecodingMap: Record<string, string> = lexicalUnsafeCharacters.reduce(
(acc, key) => ({ ...acc, [encodeURIComponent(key)]: key }),
{}
);
const lexicalUnsafeCharacterEncodingMap: Record<string, string> = lexicalUnsafeCharacters.reduce(encodeReduceFunction, {});
const lexicalUnsafeCharacterDecodingMap: Record<string, string> = lexicalUnsafeCharacters.reduce(decodeReduceFunction, {});

const lexicalSupportedTagNames = new Set([
'a',
Expand Down
6 changes: 5 additions & 1 deletion libs/designer-ui/src/lib/monitoring/values/keyvaluepairs.tsx
Expand Up @@ -46,7 +46,11 @@ export const KeyValuePairs: React.FC<ValueProps> = ({ displayName, value = {}, v
targetWidthProportion: 1,
},
];
const items = Object.entries(value).reduce((pairs: Record<string, unknown>[], [$key, $value]) => [...pairs, { $key, $value }], []);
const items = Object.entries(value).reduce((pairs: Record<string, any>[], [$key, $value]) => {
let pVal = { $key, $value };
pairs.push(pVal);
return pairs;
}, []);

return (
<section className="msla-trace-value-label">
Expand Down
Expand Up @@ -37,11 +37,9 @@ export const SimpleDictionary: React.FC<SimpleDictionaryProps> = ({
onChange?.(
values
.filter((x) => x.key && x.key !== '')
.reduce((acc, val) => {
return {
...acc,
[val.key]: val.value,
};
.reduce((acc: any, val) => {
acc[val.key] = val.value;
return acc;
}, {})
);
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
39 changes: 14 additions & 25 deletions libs/designer/src/lib/core/actions/bjsworkflow/serializer.ts
Expand Up @@ -137,10 +137,8 @@ export const serializeWorkflow = async (rootState: RootState, options?: Serializ
return references;
}

return {
...references,
[referenceKey]: referencesObject[referenceKey],
};
references[referenceKey] = referencesObject[referenceKey];
return references;
}, {});

const parameters = getWorkflowParameters(filterRecord(rootState.workflowParameters.definitions, (key, _) => key !== '')) ?? {};
Expand Down Expand Up @@ -185,10 +183,8 @@ const getActions = async (rootState: RootState, options?: SerializeOptions): Pro
(actions: LogicAppsV2.Actions, action: LogicAppsV2.ActionDefinition | null, index: number) => {
const originalId = actionsInRootGraph[index].id;
if (!isNullOrEmpty(action)) {
return {
...actions,
[getRecordEntry(idReplacements, originalId) ?? originalId]: action as LogicAppsV2.ActionDefinition,
};
actions[getRecordEntry(idReplacements, originalId) ?? originalId] = action as LogicAppsV2.ActionDefinition;
return actions;
}

return actions;
Expand Down Expand Up @@ -242,8 +238,8 @@ const getWorkflowParameters = (
: typeof defaultValue !== 'string'
? defaultValue
: JSON.parse(defaultValue);

return { ...result, [parameter?.name ?? parameterId]: parameterDefinition };
result[parameter?.name ?? parameterId] = parameterDefinition;
return result;
}, {});
};

Expand Down Expand Up @@ -376,10 +372,8 @@ const getRunAfter = (operation: LogicAppsV2.ActionDefinition, idReplacements: Re
return {};
}
return Object.entries(operation.runAfter).reduce((acc: LogicAppsV2.RunAfter, [key, value]) => {
return {
...acc,
[getRecordEntry(idReplacements, key) ?? key]: value,
};
acc[getRecordEntry(idReplacements, key) ?? key] = value;
return acc;
}, {});
};

Expand Down Expand Up @@ -447,13 +441,10 @@ export const constructInputValues = (key: string, inputs: SerializedParameter[],
return serializedParameter;
});

const pathParameters = pathTemplateParameters.reduce(
(allPathParams: Record<string, string>, current: SerializedParameter) => ({
...allPathParams,
[current.parameterName.split('.').at(-1) as string]: current.value,
}),
{}
);
const pathParameters = pathTemplateParameters.reduce((allPathParams: Record<string, string>, current: SerializedParameter) => {
allPathParams[current.parameterName.split('.').at(-1) as string] = current.value;
return allPathParams;
}, {});
const parametersToSerialize = serializedParameters.filter((param) => !isPathTemplateParameter(param));
for (const serializedParameter of parametersToSerialize) {
if (serializedParameter.info.serialization?.property?.type === PropertySerializationType.PathTemplate) {
Expand Down Expand Up @@ -812,10 +803,8 @@ const serializeSubGraph = async (
nestedActions.reduce((actions: LogicAppsV2.Actions, action: LogicAppsV2.OperationDefinition, index: number) => {
if (!isNullOrEmpty(action)) {
const actionId = nestedNodes[index].id;
return {
...actions,
[getRecordEntry(idReplacements, actionId) ?? actionId]: action,
};
actions[getRecordEntry(idReplacements, actionId) ?? actionId] = action;
return actions;
}

return actions;
Expand Down
10 changes: 7 additions & 3 deletions libs/designer/src/lib/core/state/workflow/workflowSelectors.ts
Expand Up @@ -9,7 +9,7 @@ import { createSelector } from '@reduxjs/toolkit';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import Queue from 'yocto-queue';
import type {} from "reselect";
import type {} from 'reselect';
import type {} from 'react-query';

export const getWorkflowState = (state: RootState): WorkflowState => state.workflow;
Expand Down Expand Up @@ -55,14 +55,18 @@ const reduceCollapsed =
(nodes: WorkflowNode[]): any => {
return nodes.reduce((acc: any, child: WorkflowNode) => {
const shouldFilter = condition(child);
if (!shouldFilter) return [...acc, { ...child, ...{ children: reduceCollapsed(condition)(child.children ?? []) } }];
if (!shouldFilter) {
acc.push({ ...child, ...{ children: reduceCollapsed(condition)(child.children ?? []) } });
return acc;
}

const filteredChildren = filterOutGraphChildren(child.children ?? []);
const filteredEdges =
filteredChildren.length === 2
? [createWorkflowEdge(filteredChildren[0]?.id, filteredChildren[1]?.id, WORKFLOW_EDGE_TYPES.HIDDEN_EDGE)]
: [];
return [...acc, { ...child, ...{ children: filteredChildren, edges: filteredEdges } }];
acc.push({ ...child, ...{ children: filteredChildren, edges: filteredEdges } });
return acc;
}, []);
};

Expand Down
21 changes: 9 additions & 12 deletions libs/designer/src/lib/core/utils/loops.ts
Expand Up @@ -454,18 +454,15 @@ export const isForeachActionNameForLoopsource = (
operations: Operations,
nodesMetadata: NodesMetadata
): boolean => {
const operationInfos = Object.keys(operations).reduce(
(result: Record<string, NodeOperation>, operationId) => ({
...result,
[operationId]: {
type: operations[operationId]?.type,
kind: operations[operationId]?.kind,
connectorId: '',
operationId: '',
},
}),
{}
);
const operationInfos: Record<string, NodeOperation> = {};
for (const operationId of Object.keys(operations)) {
operationInfos[operationId] = {
type: operations[operationId]?.type,
kind: operations[operationId]?.kind,
connectorId: '',
operationId: '',
};
}
const repetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos);
const sanitizedPath = sanitizeKey(expression);
const foreachAction = first((item) => {
Expand Down
18 changes: 8 additions & 10 deletions libs/designer/src/lib/core/utils/outputs.ts
Expand Up @@ -333,13 +333,11 @@ export const getUpdatedManifestForSchemaDependency = (manifest: OperationManifes
const parameters = parameterSegments.map((parameter) => parameter.slice(1, -1));
schemaToReplace = {
properties: parameters.reduce((properties: Record<string, any>, parameter: string) => {
return {
...properties,
[parameter]: {
type: Constants.SWAGGER.TYPE.STRING,
title: parameter,
},
properties[parameter] = {
type: Constants.SWAGGER.TYPE.STRING,
title: parameter,
};
return properties;
}, {}),
required: parameters,
};
Expand Down Expand Up @@ -488,10 +486,10 @@ export const loadDynamicOutputsInNode = async (
schemaOutputs = updateOutputsForBatchingTrigger(schemaOutputs, settings.splitOn?.value?.value);
}

const dynamicOutputs = Object.entries(schemaOutputs).reduce((result: Record<string, OutputInfo>, [outputKey, outputValue]) => {
return { ...result, [outputKey]: toOutputInfo(outputValue) };
}, {});

const dynamicOutputs: Record<string, OutputInfo> = {};
for (const [outputKey, outputValue] of Object.entries(schemaOutputs)) {
dynamicOutputs[outputKey] = toOutputInfo(outputValue);
}
dispatch(addDynamicOutputs({ nodeId, outputs: dynamicOutputs }));

let iconUri: string, brandColor: string;
Expand Down

0 comments on commit 3c8128c

Please sign in to comment.