← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 667: (GIS) Further (extreme) performance improvement when auto-assigning organisation units. Rev 665 n...

 

------------------------------------------------------------
revno: 667
committer: Jan Henrik Overland janhenrik.overland@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-09-11 14:09:25 +0700
message:
  (GIS) Further (extreme) performance improvement when auto-assigning organisation units. Rev 665 needs 16 seconds to assign 800+ SL facility OUs, now done in less than one second. (Thanks to Lars).
modified:
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js


--
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-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-09-10 17:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-09-11 07:09:25 +0000
@@ -253,10 +253,12 @@
         String[] rels = relations.split( RELATION_SEPARATOR );
         
         Map map = getMapByMapLayerPath( mapLayerPath );
+
+        java.util.Map<Integer, MapOrganisationUnitRelation> relationMap = getRelationshipMap( getMapOrganisationUnitRelationByMap( map ) );
         
         relationsLoop : for ( int i = 0; i < rels.length; i++ )
         {
-            String[] rel = rels[i].split( PAIR_SEPARATOR );
+            final String[] rel = rels[i].split( PAIR_SEPARATOR );
 
             if ( rel.length != 2 )
             {
@@ -272,10 +274,28 @@
                 continue relationsLoop;
             }
             
-            addOrUpdateMapOrganisationUnitRelation( map, Integer.parseInt( rel[0] ), rel[1] );
+            final int organisationUnitId = Integer.parseInt( rel[0] );
+            final String featureId = rel[1];
+            
+            MapOrganisationUnitRelation mapOrganisationUnitRelation = relationMap.get( organisationUnitId );
+
+            if ( mapOrganisationUnitRelation != null )
+            {            
+                mapOrganisationUnitRelation.setFeatureId( featureId );
+
+                updateMapOrganisationUnitRelation( mapOrganisationUnitRelation );
+            }
+            else
+            {
+                final OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+
+                mapOrganisationUnitRelation = new MapOrganisationUnitRelation( map, organisationUnit, featureId );
+
+                addMapOrganisationUnitRelation( mapOrganisationUnitRelation );
+            }            
         }
     }
-
+    
     /**
      * Provides a textual representation of the contents of a String array.
      */
@@ -290,16 +310,11 @@
         
         return buffer.append( "}" ).toString();
     }
-    
+
     public void addOrUpdateMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId )
     {
         Map map = getMapByMapLayerPath( mapLayerPath );
         
-        addOrUpdateMapOrganisationUnitRelation( map, organisationUnitId, featureId );
-    }
-    
-    private void addOrUpdateMapOrganisationUnitRelation( Map map, int organisationUnitId, String featureId )
-    {
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
 
         MapOrganisationUnitRelation mapOrganisationUnitRelation = getMapOrganisationUnitRelation( map, organisationUnit );
@@ -353,7 +368,7 @@
         Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( map
             .getOrganisationUnitLevel().getLevel() );
 
-        java.util.Map<Integer, MapOrganisationUnitRelation> relationMap = getRelationshipMap( mappingStore.getMapOrganisationUnitRelationByMap( map ) );
+        java.util.Map<Integer, MapOrganisationUnitRelation> relationMap = getRelationshipMap( getMapOrganisationUnitRelationByMap( map ) );
         
         Collection<MapOrganisationUnitRelation> availableRelations = new ArrayList<MapOrganisationUnitRelation>();
         

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2009-09-10 09:00:04 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2009-09-11 07:09:25 +0000
@@ -2620,7 +2620,7 @@
         params: { level: level, format: 'json' },
 
         success: function( responseObject ) {
-            dataReceivedAutoAssignOrganisationUnit( responseObject.responseText );
+            dataReceivedAutoAssignOrganisationUnit( responseObject.responseText );			
         },
         failure: function() {
             alert( 'Status', 'Error while retrieving data' );
@@ -2638,20 +2638,20 @@
     var count_orgunits = 0;
     var count_match = 0;
     var relations = '';
-
+	var featureName, orgunitName;
+	
     for ( var j=0; j < features.length; j++ ) {
         count_features++;
         
         for ( var i=0; i < organisationUnits.length; i++ ) {
             count_orgunits++;
-            
+			
+			// var featureName = features[j].attributes[nameColumn].split(' ').join('').toLowerCase();
+			// var orgUnitName = organisationUnits[i].name.split(' ').join('').toLowerCase();
+			
             if (features[j].attributes[nameColumn] == organisationUnits[i].name) {
-            
-                count_match++;
-                var organisationUnitId = organisationUnits[i].id;
-                var featureId = features[j].attributes[nameColumn];
-
-                relations += organisationUnitId + '::' + featureId + ';;';
+                count_match++;                
+                relations += organisationUnits[i].id + '::' + features[j].attributes[nameColumn] + ';;';
             }
         }
     }
@@ -2663,7 +2663,7 @@
 		MASK.msg = 'Assigning ' + count_match + ' organisation units...';
 	}
 	MASK.show();
-    
+
     Ext.Ajax.request({
         url: path + 'addOrUpdateMapOrganisationUnitRelations' + type,
         method: 'POST',


Follow ups