dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39907
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20214: Re-impl getMaxOfOrganisationUnitLevels using query, improves performance
------------------------------------------------------------
revno: 20214
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-17 15:53:08 +0200
message:
Re-impl getMaxOfOrganisationUnitLevels using query, improves performance
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.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/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.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-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2015-08-19 11:58:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2015-09-17 13:53:08 +0000
@@ -770,7 +770,7 @@
@Override
public List<DataElementOperand> getOperandsLikeName( String name )
{
- Collection<DataElement> dataElements = dataElementService.getDataElementsLikeName( name );
+ List<DataElement> dataElements = dataElementService.getDataElementsLikeName( name );
return getOperands( dataElements );
}
@@ -853,7 +853,7 @@
@Override
public void updateAllOptionCombos()
{
- Collection<DataElementCategoryCombo> categoryCombos = getAllDataElementCategoryCombos();
+ List<DataElementCategoryCombo> categoryCombos = getAllDataElementCategoryCombos();
for ( DataElementCategoryCombo categoryCombo : categoryCombos )
{
=== 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 2015-09-17 13:26:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-09-17 13:53:08 +0000
@@ -282,7 +282,7 @@
if ( parents != null && !parents.isEmpty() )
{
- Collection<OrganisationUnit> children = getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( parents ) );
+ List<OrganisationUnit> children = getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( parents ) );
members.retainAll( children );
}
@@ -428,46 +428,10 @@
return organisationUnitStore.getOrganisationUnits( params );
}
- //Rewrite using path
@Override
public int getNumberOfOrganisationalLevels()
{
- int maxDepth = 0;
- int depth = 0;
-
- for ( OrganisationUnit root : getRootOrganisationUnits() )
- {
- depth = getDepth( root, 1 );
-
- if ( depth > maxDepth )
- {
- maxDepth = depth;
- }
- }
-
- return maxDepth;
- }
-
- /**
- * Support method for getNumberOfOrganisationalLevels(). Finds the depth of
- * a given subtree. The parent is at the current level.
- */
- private int getDepth( OrganisationUnit parent, int currentLevel )
- {
- int maxDepth = currentLevel;
- int depth = 0;
-
- for ( OrganisationUnit child : parent.getChildren() )
- {
- depth = getDepth( child, currentLevel + 1 );
-
- if ( depth > maxDepth )
- {
- maxDepth = depth;
- }
- }
-
- return maxDepth;
+ return organisationUnitStore.getMaxLevel();
}
@Override
@@ -514,7 +478,7 @@
if ( currentUser != null && !currentUser.getUserCredentials().isSuper() )
{
- Collection<String> userDataSets = IdentifiableObjectUtils.getUids( currentUser.getUserCredentials().getAllDataSets() );
+ List<String> userDataSets = IdentifiableObjectUtils.getUids( currentUser.getUserCredentials().getAllDataSets() );
for ( Set<String> dataSets : associationMap.values() )
{
@@ -536,11 +500,11 @@
if ( currentUser != null && currentUser.getOrganisationUnits() != null )
{
- Collection<String> parentIds = getUids( currentUser.getOrganisationUnits() );
-
- Collection<OrganisationUnit> organisationUnitsWithChildren = getOrganisationUnitsWithChildren( parentIds, maxLevels );
-
- Collection<String> children = getUids( organisationUnitsWithChildren );
+ List<String> parentIds = getUids( currentUser.getOrganisationUnits() );
+
+ List<OrganisationUnit> organisationUnitsWithChildren = getOrganisationUnitsWithChildren( parentIds, maxLevels );
+
+ List<String> children = getUids( organisationUnitsWithChildren );
associationMap.keySet().retainAll( children );
}
@@ -569,7 +533,7 @@
{
Map<String, OrganisationUnit> map = new HashMap<>();
- Collection<OrganisationUnit> organisationUnits = getAllOrganisationUnits();
+ List<OrganisationUnit> organisationUnits = getAllOrganisationUnits();
for ( OrganisationUnit organisationUnit : organisationUnits )
{
@@ -731,7 +695,9 @@
List<OrganisationUnitLevel> levels = new ArrayList<>();
- for ( int i = 0; i < getNumberOfOrganisationalLevels(); i++ )
+ int levelNo = getNumberOfOrganisationalLevels();
+
+ for ( int i = 0; i < levelNo; i++ )
{
int level = i + 1;
@@ -747,7 +713,7 @@
{
Map<Integer, OrganisationUnitLevel> levelMap = new HashMap<>();
- Collection<OrganisationUnitLevel> levels = getOrganisationUnitLevels();
+ List<OrganisationUnitLevel> levels = getOrganisationUnitLevels();
for ( OrganisationUnitLevel level : levels )
{
@@ -891,7 +857,7 @@
{
// Get top search point through top level org unit which contains coordinate
- Collection<OrganisationUnit> orgUnitsTopLevel = getTopLevelOrgUnitWithPoint( longitude, latitude, 1,
+ List<OrganisationUnit> orgUnitsTopLevel = getTopLevelOrgUnitWithPoint( longitude, latitude, 1,
getNumberOfOrganisationalLevels() - 1 );
if ( orgUnitsTopLevel.size() == 1 )
@@ -904,7 +870,7 @@
if ( topOrgUnit != null )
{
- Collection<OrganisationUnit> orgUnitChildren = new ArrayList<>();
+ List<OrganisationUnit> orgUnitChildren = new ArrayList<>();
if ( targetLevel != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2015-09-17 08:13:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2015-09-17 13:53:08 +0000
@@ -190,7 +190,7 @@
{
log.info( "Validate start:" + startDate + " end: " + endDate + " sources: " + sources.size() + " group: " + group );
- Collection<Period> periods = periodService.getPeriodsBetweenDates( startDate, endDate );
+ List<Period> periods = periodService.getPeriodsBetweenDates( startDate, endDate );
Collection<ValidationRule> rules = group != null ? group.getMembers() : getAllValidationRules();
Collection<ValidationResult> results = Validator.validate( sources, periods, rules, attributeCombo, null,
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java 2015-09-17 08:13:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java 2015-09-17 13:53:08 +0000
@@ -87,7 +87,7 @@
private Map<ValidationRule, ValidationRuleExtended> ruleXMap;
- private Collection<OrganisationUnitExtended> sourceXs;
+ private Set<OrganisationUnitExtended> sourceXs;
private DataElementCategoryOptionCombo attributeCombo;