From 7f7786dceeb1f3f55c5dd0c715f85b387a7aeae4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 27 Dec 2017 17:04:36 +0100 Subject: [PATCH] Bug 19792: (QA follow-up) Move anonymous sub out of GetHierarchy Content-Type: text/plain; charset=utf-8 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 --- C4/Budgets.pm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 6d2718a..07ebc20 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -573,12 +573,20 @@ sub GetBudgetHierarchy { GROUP BY shipmentcost_budgetid |, 'budget_id'); - my $recursiveAdd; - $recursiveAdd = sub { - my ($budget, $parent) = @_; + + foreach my $budget (@sort) { + if ($budget->{budget_parent_id} == undef) { + _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); + _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}; @@ -593,15 +601,6 @@ sub GetBudgetHierarchy { $parent->{total_spent} += $budget->{total_spent}; $parent->{total_ordered} += $budget->{total_ordered}; } - }; - - foreach my $budget (@sort) { - if ($budget->{budget_parent_id} == undef) { - $recursiveAdd->($budget); - } - } - - return \@sort; } # Recursive method to add a budget and its chidren to an array -- 2.1.4