← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17181: Aalytics tables, improved performance by only joining on org unit levels which might have approva...

 

------------------------------------------------------------
revno: 17181
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-10-20 20:08:35 +0200
message:
  Aalytics tables, improved performance by only joining on org unit levels which might have approval levels
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.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/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-08-03 22:03:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-10-20 18:08:35 +0000
@@ -29,9 +29,11 @@
  */
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author Jim Grace
@@ -88,6 +90,13 @@
     List<DataApprovalLevel> getDataApprovalLevelsByOrgUnitLevel( int orgUnitLevel );
     
     /**
+     * Retrieves all org unit levels which have approval levels associated.
+     * 
+     * @return a list of org unit levels.
+     */
+    Set<OrganisationUnitLevel> getOrganisationUnitApprovalLevels();
+    
+    /**
      * Tells whether a level can move down in the list (can switch places with
      * the level below.)
      *

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-10-19 09:09:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-10-20 18:08:35 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.analytics.AnalyticsTable;
 import org.hisp.dhis.analytics.AnalyticsTableManager;
 import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.dataapproval.DataApprovalLevelService;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.jdbc.StatementBuilder;
@@ -90,6 +91,9 @@
     
     @Autowired
     protected SystemSettingManager systemSettingManager;
+    
+    @Autowired
+    protected DataApprovalLevelService dataApprovalLevelService;
    
     @Autowired
     protected StatementBuilder statementBuilder;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-10-20 15:07:35 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-10-20 18:08:35 +0000
@@ -35,6 +35,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Future;
 
@@ -230,7 +231,7 @@
         populateAndLog( sql, tableName + ", " + valueType );
     }
 
-    private String getApprovalSubquery( Collection<OrganisationUnitLevel> levels )
+    private String getApprovalSubquery()
     {
         String sql = "(" +
             "select min(dal.level) " +
@@ -241,6 +242,8 @@
             "and des.datasetapprovedata = true " +
             "and (";
         
+        Set<OrganisationUnitLevel> levels = dataApprovalLevelService.getOrganisationUnitApprovalLevels();
+        
         for ( OrganisationUnitLevel level : levels )
         {
             sql += "ous.idlevel" + level.getLevel() + " = da.organisationunitid or ";
@@ -326,7 +329,7 @@
 
         if ( isApprovalEnabled() )
         {            
-            String[] al = { quote( "approvallevel" ), "integer", getApprovalSubquery( levels ) };
+            String[] al = { quote( "approvallevel" ), "integer", getApprovalSubquery() };
             columns.add( al );
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-10-20 18:08:35 +0000
@@ -212,6 +212,26 @@
     }
 
     @Override
+    public Set<OrganisationUnitLevel> getOrganisationUnitApprovalLevels()
+    {
+        Set<OrganisationUnitLevel> orgUnitLevels = new HashSet<>();
+        
+        List<DataApprovalLevel> dataApprovalLevels = dataApprovalLevelStore.getAllDataApprovalLevels();
+        
+        for ( DataApprovalLevel level : dataApprovalLevels )
+        {
+            OrganisationUnitLevel orgUnitLevel = organisationUnitService.getOrganisationUnitLevelByLevel( level.getOrgUnitLevel() );
+            
+            if ( orgUnitLevel != null )
+            {
+                orgUnitLevels.add( orgUnitLevel );
+            }
+        }
+        
+        return orgUnitLevels;
+    }
+
+    @Override
     public boolean canDataApprovalLevelMoveDown( int level )
     {
         List<DataApprovalLevel> dataApprovalLevels = getAllDataApprovalLevels();