dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #05948
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1876: Improve the speed when persisting associations with multi OrgUnits.
------------------------------------------------------------
revno: 1876
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Tue 2010-05-18 21:03:08 +0700
message:
Improve the speed when persisting associations with multi OrgUnits.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.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/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-05-18 14:03:08 +0000
@@ -291,4 +291,6 @@
OrganisationUnitLevel getOrganisationUnitLevelByName( String name );
List<OrganisationUnitLevel> getFilledOrganisationUnitLevels();
+
+ int getNumberOfOrganisationUnits();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2010-05-18 14:03:08 +0000
@@ -188,4 +188,6 @@
* @return the OrganisationUnitLevel with the given name.
*/
OrganisationUnitLevel getOrganisationUnitLevelByName( String name );
+
+ int getNumberOfOrganisationUnits();
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2010-04-19 09:54:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2010-05-18 14:03:08 +0000
@@ -608,4 +608,10 @@
return levelMap;
}
+
+ @Override
+ public int getNumberOfOrganisationUnits()
+ {
+ return organisationUnitStore.getNumberOfOrganisationUnits();
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2010-05-10 17:50:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2010-05-18 14:03:08 +0000
@@ -356,4 +356,12 @@
return (OrganisationUnitLevel) criteria.add( Restrictions.eq( "name", name ) ).uniqueResult();
}
+
+ @Override
+ public int getNumberOfOrganisationUnits()
+ {
+ final String sql = "SELECT count(*) FROM organisationunit";
+
+ return jdbcTemplate.queryForInt( sql );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java 2010-05-17 16:13:24 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java 2010-05-18 14:03:08 +0000
@@ -50,6 +50,8 @@
private static final String SESSION_KEY_LOCKED_ORG_UNITS = "dhis-oust-locked-org-units";
private static final String SESSION_KEY_ROOT_ORG_UNITS = "dhis-oust-root-org-units";
+
+ private static final double PERSENTAGE_OF_MULTIPLE_RELOADING_ORG_UNITS = 0.3;
// -------------------------------------------------------------------------
// Dependencies
@@ -304,16 +306,33 @@
{
Set<OrganisationUnit> reloadedUnits = new HashSet<OrganisationUnit>();
- for ( OrganisationUnit unit : units )
- {
- OrganisationUnit reloadedUnit = reloadOrganisationUnit( unit );
-
- if ( reloadedUnit != null )
- {
- reloadedUnits.add( reloadedUnit );
- }
- }
-
+ int noTotal = organisationUnitService.getNumberOfOrganisationUnits();
+
+ int noSelected = units.size();
+
+ if ( (double) noSelected / noTotal > PERSENTAGE_OF_MULTIPLE_RELOADING_ORG_UNITS )
+ {
+ Collection<OrganisationUnit> allOrgUnits = organisationUnitService.getAllOrganisationUnits();
+ for ( OrganisationUnit each : allOrgUnits )
+ {
+ if ( units.contains( each ) )
+ {
+ reloadedUnits.add( each );
+ }
+ }
+ }
+ else
+ {
+ for ( OrganisationUnit unit : units )
+ {
+ OrganisationUnit reloadedUnit = reloadOrganisationUnit( unit );
+
+ if ( reloadedUnit != null )
+ {
+ reloadedUnits.add( reloadedUnit );
+ }
+ }
+ }
return reloadedUnits;
}