From 7232bc363a58037986146fa40f5e1ca8ac2eb8e6 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 4 Mar 2022 15:10:00 -1000 Subject: [PATCH] Bug 30232: Logged in user performance for CanUserManageBasket() Some acquisition methods can take borrowernumber or a Koha::Patron->unblessed. When called with logged in user, sometimes in a loop, performance will be better if fetching Koha::Patron of logged in user only once. This patch optimises call for CanUserManageBasket(). You may benchmark on a vendor with a lot of baskets. Test plan 1) 1.1) Log in to staff interface as user A with all acquisition permissions 1.2) Set system preference 'AcqViewBaskets' to 'created or managed by staff member' 1.3) Create a new basket 1.4) Copy URL, ie /cgi-bin/koha/acqui/basket.pl?basketno=2 1.5) Click on 'Baskets' tab, you see the basket in table 2) 2.1) Log in to staff interface as user B with acquisition permissions but not 'order_manage_all' 2.2) Go to URL => You don't have access to basket 2.3) Click on 'Baskets' tab => you don't see the basket in table --- acqui/basket.pl | 2 +- acqui/booksellers.pl | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/acqui/basket.pl b/acqui/basket.pl index bdc3a4d455..96a04a0f33 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -95,7 +95,7 @@ my $rs = $schema->resultset('VendorEdiAccount')->search( { vendor_id => $booksellerid, } ); $template->param( ediaccount => ($rs->count > 0)); -unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { +unless (CanUserManageBasket($logged_in_patron->unblessed, $basket, $userflags)) { $template->param( cannot_manage_basket => 1, basketno => $basketno, diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index 51de25d82b..5f9d87be8a 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -96,12 +96,8 @@ if ( $supplier_count == 1 ) { ); } -my $uid; -# FIXME This script should only be accessed by a valid logged in patron -if ($loggedinuser) { - # FIXME Should not be needed, logged in patron should be cached - $uid = Koha::Patrons->find( $loggedinuser )->userid; -} +# FIXME Should not be needed, logged in patron should be cached +my $logged_in_patron = Koha::Patrons->find( $loggedinuser ); my $userenv = C4::Context::userenv; my $viewbaskets = C4::Context->preference('AcqViewBaskets'); @@ -111,7 +107,7 @@ my $userbranch = $userenv->{branch}; my $budgets = GetBudgetHierarchy; my $has_budgets = 0; foreach my $r (@{$budgets}) { - next unless (CanUserUseBudget($loggedinuser, $r, $userflags)); + next unless (CanUserUseBudget($logged_in_patron->unblessed, $r, $userflags)); $has_budgets = 1; last; -- 2.35.1