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.
This commit is contained in:
parent
63343353d2
commit
bc3583104d
3 changed files with 35 additions and 55 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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<ResourceWithItsLoadRatios> getAllResources() {
|
||||
|
||||
List<ResourceWithItsLoadRatios> result = new ArrayList<ResourceWithItsLoadRatios>();
|
||||
|
||||
// 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<? extends Resource> listResources = query().byResourceType(
|
||||
getType()).execute();
|
||||
|
||||
result = addLoadRatiosCalculations(listResources);
|
||||
}
|
||||
return result;
|
||||
return addLoadRatiosCalculations(query().byResourceType(
|
||||
getType()).execute());
|
||||
}
|
||||
|
||||
private List<ResourceWithItsLoadRatios> 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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue