← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20109: Oust manager, performance improvement

 

------------------------------------------------------------
revno: 20109
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-09-13 18:12:09 +0200
message:
  Oust manager, performance improvement
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.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-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java	2015-09-13 13:48:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java	2015-09-13 16:12:09 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
+import com.google.common.collect.Sets;
 import com.opensymphony.xwork2.ActionContext;
 
 /**
@@ -244,24 +245,19 @@
 
     private Collection<OrganisationUnit> reloadOrganisationUnits( Collection<OrganisationUnit> units )
     {
-        Set<OrganisationUnit> reloadedUnits = new HashSet<>();
-
         int noSelected = units.size();
 
         if ( noSelected > LIMIT_SELECT_ALL_ORG_UNITS ) // Select all at once
         {
-            Collection<OrganisationUnit> allOrgUnits = organisationUnitService.getAllOrganisationUnits();
-
-            for ( OrganisationUnit unit : allOrgUnits )
-            {
-                if ( units.contains( unit ) )
-                {
-                    reloadedUnits.add( unit );
-                }
-            }
+            Set<OrganisationUnit> orgUnits = Sets.newHashSet( organisationUnitService.getAllOrganisationUnits() );
+            orgUnits.retainAll( Sets.newHashSet( units ) );
+            
+            return orgUnits;
         }
         else // Select one by one
         {
+            Set<OrganisationUnit> reloadedUnits = new HashSet<>();
+            
             for ( OrganisationUnit unit : units )
             {
                 OrganisationUnit reloadedUnit = reloadOrganisationUnit( unit );
@@ -271,8 +267,9 @@
                     reloadedUnits.add( reloadedUnit );
                 }
             }
-        }
-        return reloadedUnits;
+            
+            return reloadedUnits;
+        }        
     }
 
     // -------------------------------------------------------------------------