← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4244: Minor performance improvement in vvalidation, no need to check right side if left side is null

 

------------------------------------------------------------
revno: 4244
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-08-02 13:23:53 +0200
message:
  Minor performance improvement in vvalidation, no need to check right side if left side is null
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2011-05-20 16:00:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2011-08-02 11:23:53 +0000
@@ -303,15 +303,19 @@
                 if ( validationRule.getPeriodType() != null && validationRule.getPeriodType().equals( period.getPeriodType() ) )
                 {
                     leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), period, source, true, aggregate, null );
-                    rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source, true, aggregate, null );
-        
-                    if ( leftSide != null && rightSide != null )
+                    
+                    if ( leftSide != null )
                     {
-                        violation = !expressionIsTrue( leftSide, validationRule.getOperator(), rightSide );
-        
-                        if ( violation )
+                        rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source, true, aggregate, null );
+            
+                        if ( rightSide != null )
                         {
-                            validationViolations.add( new ValidationResult( period, source, validationRule, getRounded( leftSide, DECIMALS ), getRounded( rightSide, DECIMALS ) ) );
+                            violation = !expressionIsTrue( leftSide, validationRule.getOperator(), rightSide );
+            
+                            if ( violation )
+                            {
+                                validationViolations.add( new ValidationResult( period, source, validationRule, getRounded( leftSide, DECIMALS ), getRounded( rightSide, DECIMALS ) ) );
+                            }
                         }
                     }
                 }
@@ -333,6 +337,8 @@
     {
         final Set<ValidationRule> relevantValidationRules = new HashSet<ValidationRule>();
 
+        //TODO move getDataElementsInExpression out of for-loop
+        
         for ( ValidationRule validationRule : getAllValidationRules() )
         {
             for ( DataElement dataElement : dataElements )