From bc3583104da2b87418b15ff75f32a15a5de44a18 Mon Sep 17 00:00:00 2001 From: Oscar Gonzalez Fernandez Date: Sun, 20 Apr 2014 17:32:39 +0200 Subject: [PATCH] Fix performance regression When opening the `resource allocation modal window` (double-click on a task), the advanced search was calculating the load of the resources when it should do it when clicking advanced search button. This leads to a big delay when opening the `resource allocation modal window` if there is a moderate amount of data. Now these calculations are only done when clicking advanced search button and the `resource allocation modal window` is opened almost instantly. --- .../components/NewAllocationSelector.java | 14 ++--- .../ResourceAllocationController.java | 21 ++----- .../NewAllocationSelectorController.java | 55 ++++++++----------- 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java index f6c529c36..a3df78f40 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java @@ -21,9 +21,9 @@ package org.libreplan.web.common.components; -import java.util.Date; import java.util.List; +import org.joda.time.LocalDate; import org.libreplan.business.resources.daos.IResourcesSearcher; import org.libreplan.business.resources.daos.IResourcesSearcher.IResourcesQuery; import org.libreplan.business.resources.entities.Criterion; @@ -169,12 +169,12 @@ public class NewAllocationSelector extends AllocationSelector { this.behaviour = ResourceAllocationBehaviour.valueOf(behaviour); } - public void setEndFilteringDate(Date d) { - getController().setEndFilteringDate(d); - } - - public void setStartFilteringDate(Date d) { - getController().setStartFilteringDate(d); + public void open(LocalDate start, LocalDate end) { + start = start + .minusDays(DAYS_LEAD_LAG_TO_TASK_LIMITS_DATES_FILTERING_INITIALIZATION); + end = end + .plusDays(DAYS_LEAD_LAG_TO_TASK_LIMITS_DATES_FILTERING_INITIALIZATION); + getController().open(start, end); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java index 6a07051b9..4223cb24a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java @@ -323,23 +323,14 @@ public class ResourceAllocationController extends GenericForwardComposer { } public void goToAdvancedSearch() { - newAllocationSelector - .setStartFilteringDate(LocalDate - .fromDateFields(resourceAllocationModel.getTaskStart()) - .minusDays( - NewAllocationSelector.DAYS_LEAD_LAG_TO_TASK_LIMITS_DATES_FILTERING_INITIALIZATION) - .toDateTimeAtStartOfDay().toDate()); - newAllocationSelector - .setEndFilteringDate(LocalDate - .fromDateFields(resourceAllocationModel.getTaskEnd()) - .plusDays( - NewAllocationSelector.DAYS_LEAD_LAG_TO_TASK_LIMITS_DATES_FILTERING_INITIALIZATION) - .toDateTimeAtStartOfDay().toDate()); applyButton.setVisible(false); workerSearchTab.setSelected(true); - // The initial search and ratio load calculations is raised - // on going to advanced search - newAllocationSelector.clearAll(); + + LocalDate start = LocalDate + .fromDateFields(resourceAllocationModel.getTaskStart()); + LocalDate end = LocalDate + .fromDateFields(resourceAllocationModel.getTaskEnd()); + newAllocationSelector.open(start, end); } /** diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java index fc662fea6..4fac1d644 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java @@ -125,20 +125,10 @@ public class NewAllocationSelectorController extends initializeCriteriaTree(); initializeListboxResources(); initializeAllocationTypeSelector(); - initializeFilteringDates(); + initializeFilteringDatesConstraints(); } - private void initializeFilteringDates() { - // Start and end filtering dates are initialized here because - // they cannot be empty and must have always a value. The - // task start date and task end date are not available at the first - // rendering. Thus, the current date and current date + 1 day are used - // as the value to initialize the components although will - // never be visible by the user. - Date initDate = new Date(); - setStartFilteringDate(initDate); - setEndFilteringDate(LocalDate.fromDateFields(initDate).plusDays(1) - .toDateTimeAtStartOfDay().toDate()); + private void initializeFilteringDatesConstraints() { startDateLoadRatiosDatebox .setConstraint(checkConstraintFilteringDate()); endDateLoadRatiosDatebox.setConstraint(checkConstraintFilteringDate()); @@ -237,22 +227,8 @@ public class NewAllocationSelectorController extends } private List getAllResources() { - - List result = new ArrayList(); - - // The search is only done in case that the endFilteringDate and - // startFilteringDate are initialized. This happens when the - // user does the advanced search visible by clicking on the - // AdvancedSearch button - if ((startDateLoadRatiosDatebox.getValue() != null) - && (endDateLoadRatiosDatebox.getValue() != null)) { - - List listResources = query().byResourceType( - getType()).execute(); - - result = addLoadRatiosCalculations(listResources); - } - return result; + return addLoadRatiosCalculations(query().byResourceType( + getType()).execute()); } private List addLoadRatiosCalculations( @@ -416,10 +392,16 @@ public class NewAllocationSelectorController extends @Override public void clearAll() { + } + + public void open(LocalDate start, LocalDate end) { + setStartFilteringDate(start); + setEndFilteringDate(end); + refreshListBoxResources(); - criterionsTree.setModel(getCriterions()); clearSelection(listBoxResources); clearSelection(criterionsTree); + criterionsTree.setModel(getCriterions()); doInitialSelection(); } @@ -710,12 +692,19 @@ public class NewAllocationSelectorController extends return listBoxResources.isMultiple(); } - public void setEndFilteringDate(Date d) { - endDateLoadRatiosDatebox.setValue(d); + public void setEndFilteringDate(LocalDate d) { + endDateLoadRatiosDatebox.setValue(asDate(d)); } - public void setStartFilteringDate(Date d) { - startDateLoadRatiosDatebox.setValue(d); + public void setStartFilteringDate(LocalDate date) { + startDateLoadRatiosDatebox.setValue(asDate(date)); + } + + private static Date asDate(LocalDate date) { + if (date == null) { + return null; + } + return date.toDateTimeAtStartOfDay().toDate(); } public void updateLoadRatios() {