← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19304: performance optimizations in DXF2 EnrollmentService, adds explicit flushing, speeds up bulk impor...

 

------------------------------------------------------------
revno: 19304
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-08 10:34:10 +0700
message:
  performance optimizations in DXF2 EnrollmentService, adds explicit flushing, speeds up bulk imports about 5x
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.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/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-06-08 03:29:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-06-08 03:34:10 +0000
@@ -30,6 +30,7 @@
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import org.hibernate.SessionFactory;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
@@ -113,6 +114,9 @@
     @Autowired
     protected UserService userService;
 
+    @Autowired
+    protected SessionFactory sessionFactory;
+
     // -------------------------------------------------------------------------
     // READ
     // -------------------------------------------------------------------------
@@ -341,10 +345,19 @@
     public ImportSummaries addEnrollments( List<Enrollment> enrollments )
     {
         ImportSummaries importSummaries = new ImportSummaries();
+        int counter = 0;
 
         for ( Enrollment enrollment : enrollments )
         {
             importSummaries.addImportSummary( addEnrollment( enrollment ) );
+
+            if ( counter % FLUSH_FREQUENCY == 0 )
+            {
+                sessionFactory.getCurrentSession().flush();
+                sessionFactory.getCurrentSession().clear();
+            }
+
+            counter++;
         }
 
         return importSummaries;
@@ -435,10 +448,19 @@
     public ImportSummaries updateEnrollments( List<Enrollment> enrollments )
     {
         ImportSummaries importSummaries = new ImportSummaries();
+        int counter = 0;
 
         for ( Enrollment enrollment : enrollments )
         {
             importSummaries.addImportSummary( updateEnrollment( enrollment ) );
+
+            if ( counter % FLUSH_FREQUENCY == 0 )
+            {
+                sessionFactory.getCurrentSession().flush();
+                sessionFactory.getCurrentSession().clear();
+            }
+
+            counter++;
         }
 
         return importSummaries;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2015-06-08 03:29:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2015-06-08 03:34:10 +0000
@@ -47,6 +47,8 @@
  */
 public interface EnrollmentService
 {
+    int FLUSH_FREQUENCY = 20;
+
     // -------------------------------------------------------------------------
     // READ
     // -------------------------------------------------------------------------