dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19349
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8399: Made message recipients search scale better through queries and caching
------------------------------------------------------------
revno: 8399
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-10-06 12:40:16 +0200
message:
Made message recipients search scale better through queries and caching
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.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/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-09-24 06:28:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-10-06 10:40:16 +0000
@@ -93,7 +93,9 @@
*/
Collection<User> getAllUsers();
- Collection<User> getAllUsersBetween(int first, int max);
+ Collection<User> getAllUsersBetween( int first, int max );
+
+ Collection<User> getAllUsersBetweenByName( String name, int first, int max );
Collection<User> getUsersByLastUpdated(Date lastUpdated);
@@ -133,8 +135,6 @@
int getUserCountByName( String name );
- Collection<User> getUsersByName(String name);
-
int getUsersWithoutOrganisationUnitCount();
int getUsersWithoutOrganisationUnitCountByName( String name );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-09-24 06:28:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-10-06 10:40:16 +0000
@@ -188,6 +188,12 @@
{
return userStore.getBetween( first, max );
}
+
+ @Override
+ public Collection<User> getAllUsersBetweenByName( String name, int first, int max )
+ {
+ return userStore.getBetweenByName( name, first, max );
+ }
@Override
public Collection<User> getUsersByLastUpdated( Date lastUpdated )
@@ -392,23 +398,6 @@
return userCredentialsStore.getUserCountByName( userName );
}
- @Override
- public Collection<User> getUsersByName( String name )
- {
- Collection<User> users = userStore.getAll();
- Collection<User> result = new HashSet<User>();
-
- for(User user : users)
- {
- if(user.getName().toUpperCase().contains( name.toUpperCase() ))
- {
- result.add( user );
- }
- }
-
- return result;
- }
-
public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max )
{
return userCredentialsStore.getUsersWithoutOrganisationUnitBetween( first, max );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-08-21 07:59:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-10-06 10:40:16 +0000
@@ -33,6 +33,7 @@
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.user.User;
@@ -59,6 +60,18 @@
return criteria.list();
}
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<User> getBetweenByName( String name, int first, int max )
+ {
+ Criteria criteria = getCriteria();
+ criteria.add( Restrictions.or( Restrictions.ilike( "surname", "%" + name + "%" ), Restrictions.ilike( "firstName", "%" + name + "%" ) ) );
+ criteria.addOrder( Order.asc( "surname" ) ).addOrder( Order.asc( "firstName" ) );
+ criteria.setFirstResult( first );
+ criteria.setMaxResults( max );
+ return criteria.list();
+ }
+
public Collection<User> getUsersWithoutOrganisationUnit()
{
Collection<User> users = getAll();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-01 14:21:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-06 10:40:16 +0000
@@ -255,7 +255,7 @@
}
else
{
- recipients.setUsers( new HashSet<User>( userService.getUsersByName( filter ) ) );
+ recipients.setUsers( new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java 2012-09-24 06:28:31 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java 2012-10-06 10:40:16 +0000
@@ -27,8 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_JSON;
import com.opensymphony.xwork2.Action;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.struts2.ServletActionContext;
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
@@ -44,6 +50,8 @@
public class GetMessageRecipientsAction
implements Action
{
+ private static final int MAX_PER_OBJECT = 15;
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -54,6 +62,9 @@
@Autowired
private UserGroupService userGroupService;
+ @Autowired
+ private ContextUtils contextUtils;
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -67,13 +78,13 @@
private Set<User> users = new HashSet<User>();
- private Set<UserGroup> userGroups = new HashSet<UserGroup>();
-
public Set<User> getUsers()
{
return users;
}
+ private Set<UserGroup> userGroups = new HashSet<UserGroup>();
+
public Set<UserGroup> getUserGroups()
{
return userGroups;
@@ -86,17 +97,17 @@
@Override
public String execute() throws Exception
{
- if ( filter == null || filter.isEmpty() )
- {
- users = new HashSet<User>( userService.getAllUsers() );
- userGroups = new HashSet<UserGroup>( userGroupService.getAllUserGroups() );
- }
- else
- {
- users = new HashSet<User>( userService.getUsersByName( filter ) );
- userGroups = new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) );
+ filter = StringUtils.trimToNull( filter );
+
+ if ( filter != null )
+ {
+ users = new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, MAX_PER_OBJECT ) );
+
+ userGroups = new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, MAX_PER_OBJECT ) );
}
+ contextUtils.configureResponse( ServletActionContext.getResponse(), CONTENT_TYPE_JSON, CacheStrategy.CACHE_1_HOUR );
+
return SUCCESS;
}
}