From ff8a5e9f12b43a14fb7166ca30f1de572a1c0c1f Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 17 Mar 2015 14:50:14 +0100 Subject: [PATCH] Bug 13852 - Manage C4::VirtualShelves in C4::Auth for performance Content-Type: text/plain; charset=utf-8 In C4::Auth there is a use C4::VirtualShelves. Virtualshelves are displayed in all OPAC pages, but not in intranet. For performance, we should move this into a require only for opac pages. This patch adds a condition to fetch virtualshelves only if opac and moves the dependancy on C4::VirtualShelves into require calls. On my desktop, I have those compilation times for C4/Auth.pm : - Without patch : 0,41 seconds - With patch : 0,22 seconds This performance improvement is very usefull for pages that only use a few as dependancy, like errors/404.pl Test plan : - Be sure there are some public lists - Apply patch - Go to opac (not logged-in) - Click on "Lists" - Check you see the public lists - Login with a user - Be sure this user has some private lists - Click on "Lists" - Check you see the public and private lists - Logout - Go to /cgi-bin/koha/opac-reserve.pl - You see the loggin page - Click on "Lists" - Check you see the public lists - Go to intranet - Check you can loggin Signed-off-by: Marcel de Rooy --- C4/Auth.pm | 32 +++++++++++++++++++------------- 1 files changed, 19 insertions(+), 13 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 22f1e8e..5986037 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -30,7 +30,6 @@ use C4::Templates; # to get the template use C4::Languages; use C4::Branch; # GetBranches use C4::Search::History; -use C4::VirtualShelves; use Koha::AuthUtils qw(hash_password); use POSIX qw/strftime/; use List::MoreUtils qw/ any /; @@ -199,13 +198,16 @@ sub get_template_and_user { $template->param( loggedinusernumber => $borrowernumber ); $template->param( sessionID => $sessionID ); - my ( $total, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $borrowernumber, 'MASTHEAD' ); - $template->param( - pubshelves => $total->{pubtotal}, - pubshelvesloop => $pubshelves, - barshelves => $total->{bartotal}, - barshelvesloop => $barshelves, - ); + if ( $in->{'type'} eq 'opac' ) { + require C4::VirtualShelves; + my ( $total, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $borrowernumber, 'MASTHEAD' ); + $template->param( + pubshelves => $total->{pubtotal}, + pubshelvesloop => $pubshelves, + barshelves => $total->{bartotal}, + barshelvesloop => $barshelves, + ); + } my ($borr) = C4::Members::GetMemberDetails($borrowernumber); my @bordat; @@ -334,11 +336,14 @@ sub get_template_and_user { $template->param( sessionID => $sessionID ); - my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' ); - $template->param( - pubshelves => $total->{pubtotal}, - pubshelvesloop => $pubshelves, - ); + if ( $in->{'type'} eq 'opac' ){ + require C4::VirtualShelves; + my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' ); + $template->param( + pubshelves => $total->{pubtotal}, + pubshelvesloop => $pubshelves, + ); + } } # Anonymous opac search history @@ -1203,6 +1208,7 @@ sub checkauth { $template->param( loginprompt => 1 ) unless $info{'nopermission'}; if ( $type eq 'opac' ) { + require C4::VirtualShelves; my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' ); $template->param( pubshelves => $total->{pubtotal}, -- 1.7.7.6