Skip to content

Commit

Permalink
Merge pull request #1271 from dhis2/cp/bugfixes/DHIS2-10070-performan…
Browse files Browse the repository at this point in the history
…ce-on-rules-engine

fix: DHIS2-10070 improves rules engine performance
  • Loading branch information
Bekkalizer authored Dec 8, 2020
2 parents 5f40665 + 3b45739 commit de1077c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ function convertFormValuesToClientValues(formValues: {[key: string]: any}, rende

function getValidFormValues(formValues: { [key: string]: any }, fieldsValidation: { [key: string]: boolean }) {
return Object.keys(formValues)
.reduce((accValidFormValues, key) => {
const isValid = fieldsValidation[key];
accValidFormValues[key] = isValid ? formValues[key] : null;
return accValidFormValues;
}, {});
.filter(key => fieldsValidation[key])
.reduce((accValidFormValues, key) => (
{ ...accValidFormValues, [key]: formValues[key] }
), {});
}

function getFieldsValidationForForm(sectionsFieldsUI: Object, formId: string) {
Expand Down Expand Up @@ -72,7 +71,6 @@ export function getCurrentClientValues(
fieldValidations;

const validFormValues = getValidFormValues(updatedCurrentFormData, updatedFieldValidations);

const clientData = convertFormValuesToClientValues(validFormValues, foundation);
return clientData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ function filterFieldsHideEffects(
}

const elementIds = Object.keys(hideEffects);
const compulsoryElements = foundation.getElements().filter(({ compulsory }) => compulsory);

return elementIds
.filter((elementId) => {
const element = foundation.getElement(elementId);
const dataCompulsory = element && element.compulsory;
const { compulsory: elementIsCompulsory } =
compulsoryElements.find(({ id }) => id === elementId) || {};

const compulsoryEffect = makeCompulsoryEffects[elementId];
return !(dataCompulsory || compulsoryEffect);
return !(elementIsCompulsory || compulsoryEffect);
})
.reduce((accFilteredEffects, elementId) => {
accFilteredEffects[elementId] = hideEffects[elementId];
Expand Down

0 comments on commit de1077c

Please sign in to comment.