← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21819: Speed up metadata export using Query.setUser(), gets rid of repeated getCurrentUser() calls

 

------------------------------------------------------------
revno: 21819
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-27 14:34:02 +0700
message:
  Speed up metadata export using Query.setUser(), gets rid of repeated getCurrentUser() calls
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.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/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2016-01-27 07:34:02 +0000
@@ -95,7 +95,7 @@
 
     public DashboardItem()
     {
-        setAutoFields();
+
     }
 
     public DashboardItem( String uid )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2016-01-04 06:04:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2016-01-27 07:34:02 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.schema.Property;
 import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.ArrayList;
@@ -54,6 +55,9 @@
     implements QueryEngine<T>
 {
     @Autowired
+    private CurrentUserService currentUserService;
+
+    @Autowired
     private final List<HibernateGenericStore<T>> hibernateGenericStores = new ArrayList<>();
 
     private Map<Class<?>, HibernateGenericStore<T>> stores = new HashMap<>();
@@ -76,7 +80,12 @@
             return new ArrayList<>();
         }
 
-        Criteria criteria = buildCriteria( store.getSharingCriteria(), query );
+        if ( query.getUser() == null )
+        {
+            query.setUser( currentUserService.getCurrentUser() );
+        }
+
+        Criteria criteria = buildCriteria( store.getSharingCriteria( query.getUser() ), query );
 
         if ( criteria == null )
         {
@@ -108,7 +117,12 @@
             return 0;
         }
 
-        Criteria criteria = buildCriteria( store.getSharingCriteria(), countQuery );
+        if ( query.getUser() == null )
+        {
+            query.setUser( currentUserService.getCurrentUser() );
+        }
+
+        Criteria criteria = buildCriteria( store.getSharingCriteria( query.getUser() ), countQuery );
 
         if ( criteria == null )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java	2016-01-05 07:53:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java	2016-01-27 07:34:02 +0000
@@ -31,6 +31,7 @@
 import com.google.common.base.MoreObjects;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.user.User;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -41,6 +42,8 @@
  */
 public class Query extends Criteria
 {
+    private User user;
+
     private List<Order> orders = new ArrayList<>();
 
     private Integer firstResult = 0;
@@ -92,6 +95,16 @@
         orders.clear();
     }
 
+    public User getUser()
+    {
+        return user;
+    }
+
+    public void setUser( User user )
+    {
+        this.user = user;
+    }
+
     public Integer getFirstResult()
     {
         return firstResult;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-01-27 07:18:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-01-27 07:34:02 +0000
@@ -35,6 +35,8 @@
 import org.hisp.dhis.query.QueryService;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -57,6 +59,9 @@
     @Autowired
     private QueryService queryService;
 
+    @Autowired
+    private CurrentUserService currentUserService;
+
     @Override
     @SuppressWarnings( "unchecked" )
     public Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> getMetadata( MetadataExportParams params )
@@ -71,6 +76,8 @@
 
         log.info( "Export started at " + new Date() );
 
+        User defaultUser = currentUserService.getCurrentUser();
+
         for ( Class<? extends IdentifiableObject> klass : params.getClasses() )
         {
             Query query;
@@ -85,6 +92,11 @@
                 query = Query.from( schema );
             }
 
+            if ( query.getUser() == null )
+            {
+                query.setUser( defaultUser );
+            }
+
             List<? extends IdentifiableObject> objects = queryService.query( query );
             log.info( "Exported " + objects.size() + " objects of type " + klass.getSimpleName() );
             metadata.put( klass, objects );

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2016-01-27 07:34:02 +0000
@@ -200,12 +200,20 @@
         return getSharingCriteria( "r%" );
     }
 
-    private Criteria getSharingCriteria( String access )
+    public final Criteria getSharingCriteria( String access )
+    {
+        return getSharingCriteria( currentUserService.getCurrentUser(), access );
+    }
+
+    public final Criteria getSharingCriteria( User user )
+    {
+        return getSharingCriteria( user, "r%" );
+    }
+
+    private Criteria getSharingCriteria( User user, String access )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( getClazz(), "c" ).setCacheable( cacheable );
 
-        User user = currentUserService.getCurrentUser();
-
         if ( !sharingEnabled( user ) || user == null )
         {
             return criteria;