← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20108: Performance improvement for update* methods using parallel streams

 

------------------------------------------------------------
revno: 20108
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-09-13 18:04:26 +0200
message:
  Performance improvement for update* methods using parallel streams
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2015-09-13 15:47:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2015-09-13 16:04:26 +0000
@@ -292,16 +292,9 @@
     {
         Set<OrganisationUnit> toRemove = Sets.difference( sources, updates );
         Set<OrganisationUnit> toAdd = Sets.difference( updates, sources );
-
-        for ( OrganisationUnit unit : toRemove )
-        {
-            unit.getDataSets().remove( this );
-        }
         
-        for ( OrganisationUnit unit : toAdd )
-        {
-            unit.getDataSets().add( this );
-        }
+        toRemove.parallelStream().forEach( u -> u.getDataSets().remove( this ) );
+        toAdd.parallelStream().forEach( u -> u.getDataSets().add( this ) );
         
         sources.clear();
         sources.addAll( updates );
@@ -324,15 +317,8 @@
         Set<DataElement> toRemove = Sets.difference( dataElements, updates );
         Set<DataElement> toAdd = Sets.difference( updates, dataElements );
         
-        for ( DataElement element : toRemove )
-        {
-            element.getDataSets().remove( this );
-        }
-        
-        for ( DataElement element : toAdd )
-        {
-            element.getDataSets().add( this );
-        }
+        toRemove.parallelStream().forEach( d -> d.getDataSets().remove( this ) );
+        toAdd.parallelStream().forEach( d -> d.getDataSets().add( this ) );
         
         dataElements.clear();
         dataElements.addAll( updates );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2015-09-13 15:47:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2015-09-13 16:04:26 +0000
@@ -278,16 +278,9 @@
         Set<DataSet> toRemove = Sets.difference( dataSets, updates );
         Set<DataSet> toAdd = Sets.difference( updates, dataSets );
         
-        for ( DataSet dataSet : toRemove )
-        {
-            dataSet.getSources().remove( this );
-        }
-        
-        for ( DataSet dataSet : toAdd )
-        {
-            dataSet.getSources().add( this );
-        }
-        
+        toRemove.parallelStream().forEach( d -> d.getSources().remove( this ) );
+        toAdd.parallelStream().forEach( d -> d.getSources().add( this ) );
+                
         dataSets.clear();
         dataSets.addAll( updates );
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-09-13 15:47:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-09-13 16:04:26 +0000
@@ -171,15 +171,8 @@
         Set<OrganisationUnit> toRemove = Sets.difference( organisationUnits, updates );
         Set<OrganisationUnit> toAdd = Sets.difference( updates, organisationUnits );
         
-        for ( OrganisationUnit unit : toRemove )
-        {
-            unit.getPrograms().remove( this );
-        }
-
-        for ( OrganisationUnit unit : toAdd )
-        {
-            unit.getPrograms().add( this );
-        }
+        toRemove.parallelStream().forEach( u -> u.getPrograms().remove( this ) );
+        toAdd.parallelStream().forEach( u -> u.getPrograms().add( this ) );
         
         organisationUnits.clear();
         organisationUnits.addAll( updates );