← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17012: add program cache map to AbstractEventService, speeds up event imports by about 90%

 

------------------------------------------------------------
revno: 17012
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-09 13:32:38 +0700
message:
  add program cache map to AbstractEventService, speeds up event imports by about 90%
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-10-08 12:58:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-10-09 06:32:38 +0000
@@ -201,9 +201,9 @@
     @Override
     public ImportSummary addEvent( Event event, ImportOptions importOptions )
     {
-        Program program = programService.getProgram( event.getProgram() );
+        Program program = getProgram( event.getProgram() );
         ProgramInstance programInstance;
-        ProgramStage programStage = programStageService.getProgramStage( event.getProgramStage() );
+        ProgramStage programStage = getProgramStage( event.getProgramStage() );
         ProgramStageInstance programStageInstance = null;
 
         if ( importOptions == null )
@@ -962,4 +962,32 @@
 
         return organisationUnit;
     }
+
+    private Map<String, Program> programMap = new HashMap<>();
+
+    private Program getProgram( String id )
+    {
+        Program program;
+
+        if ( programMap.containsKey( id ) )
+        {
+            program = programMap.get( id );
+        }
+        else
+        {
+            program = programService.getProgram( id );
+
+            if ( program != null )
+            {
+                programMap.put( id, program );
+            }
+        }
+
+        return program;
+    }
+
+    private ProgramStage getProgramStage( String id )
+    {
+        return programStageService.getProgramStage( id );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-10-08 06:12:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-10-09 06:32:38 +0000
@@ -500,7 +500,7 @@
 
         if ( !importOptions.isAsync() )
         {
-            ImportSummaries importSummaries = eventService.addEvents( events.getEvents(), importOptions );
+            ImportSummaries importSummaries = eventService.addEvents( events.getEvents(), importOptions, null );
             JacksonUtils.toJson( response.getOutputStream(), importSummaries );
         }
         else