Bug 19792: (QA follow-up) Move anonymous sub out of GetHierarchy

Test plan:
Run t/db_dependent/Budgets.t.
Without both patches, running the test is slower than with only the first
or both patches.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2017-12-27 17:04:36 +01:00 committed by Jonathan Druart
parent 1edd7f8265
commit 8f3f232175
1 changed files with 22 additions and 23 deletions

View File

@ -573,37 +573,36 @@ sub GetBudgetHierarchy {
GROUP BY shipmentcost_budgetid
|, 'budget_id');
my $recursiveAdd;
$recursiveAdd = sub {
my ($budget, $parent) = @_;
foreach my $child (@{$budget->{children}}){
$recursiveAdd->($child, $budget);
}
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost};
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered};
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost};
$budget->{total_spent} += $budget->{budget_spent};
$budget->{total_ordered} += $budget->{budget_ordered};
if ($parent) {
$parent->{total_spent} += $budget->{total_spent};
$parent->{total_ordered} += $budget->{total_ordered};
}
};
foreach my $budget (@sort) {
if ($budget->{budget_parent_id} == undef) {
$recursiveAdd->($budget);
_recursiveAdd( $budget, undef, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
}
}
return \@sort;
}
sub _recursiveAdd {
my ($budget, $parent, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment ) = @_;
foreach my $child (@{$budget->{children}}){
_recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
}
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent};
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost};
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered};
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost};
$budget->{total_spent} += $budget->{budget_spent};
$budget->{total_ordered} += $budget->{budget_ordered};
if ($parent) {
$parent->{total_spent} += $budget->{total_spent};
$parent->{total_ordered} += $budget->{total_ordered};
}
}
# Recursive method to add a budget and its chidren to an array
sub _add_budget_children {
my $res = shift;