From d69a027e06a94f3af59d89dc0ea1a83acc66d0e6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 4 Nov 2019 10:59:26 -0500 Subject: [PATCH] Bug 23966 - Branch Transfer Limits editor unusable for sites with many libraries and ccodes/itemtypes Right now the branch transfer limits editor works fine if an instance has a small number of libraries and ccodes/itemtypes, but for large consortia who may have over 100 branches and ccodes/itemtypes, the editor page can take literal minutes to load ( we have partners where the page load time is 7-8 minutes ). This is because we run a separate database query for each limit. We should use a single query to find all the limits for this page. Test Plan: 1) Enable BranchTransferLimits 2) Create some limits, test adding and removing limits 3) Apply this patch 4) Restart all the things! 5) Reload the page, you should see the same limits in place as before 6) Test adding and removing limits, everything should behave the same as it did before the patch was applied! --- admin/branch_transfer_limits.pl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl index 82a8d214c9..38b70a5e04 100755 --- a/admin/branch_transfer_limits.pl +++ b/admin/branch_transfer_limits.pl @@ -25,7 +25,8 @@ use C4::Auth; use C4::Context; use C4::Output; use C4::Koha; -use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit }; +use C4::Circulation qw{ DeleteBranchTransferLimits CreateBranchTransferLimit }; +use Koha::Item::Transfer::Limits; my $input = new CGI; @@ -75,7 +76,6 @@ while ( my $row = $sth->fetchrow_hashref ) { if ( $input->param('updateLimits') ) { DeleteBranchTransferLimits($branchcode); - foreach my $code ( @codes ) { foreach my $toBranch ( @branchcodes ) { my $isSet = not $input->param( $code . "_" . $toBranch); @@ -95,6 +95,12 @@ foreach my $branchcode ( @branchcodes ) { } my $branchcount = scalar(@branchcode_loop); +my $limits_rs = Koha::Item::Transfer::Limits->search( { fromBranch => $branchcode } ); +my $limits = {}; +while ( my $l = $limits_rs->next ) { + $limits->{ $l->toBranch } = $l->$limitType; +} + ## Build the default data my @codes_loop; foreach my $code ( @codes ) { @@ -104,17 +110,15 @@ foreach my $code ( @codes ) { $row_data{ to_branch_loop } = \@to_branch_loop; foreach my $toBranch ( @branchcodes ) { my %row_data; - my $isChecked = IsBranchTransferAllowed( $toBranch, $branchcode, $code ); $row_data{ code } = $code; $row_data{ toBranch } = $toBranch; - $row_data{ isChecked } = $isChecked; + $row_data{ isChecked } = $limits->{ $toBranch } ? 0 : 1; push( @to_branch_loop, \%row_data ); } push( @codes_loop, \%row_data ); } - $template->param( branchcount => $branchcount, codes_loop => \@codes_loop, -- 2.21.0 (Apple Git-122.2)