From 95f725f28ac54b273eb80786d90a92635a4244ee Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Dec 2015 17:00:10 +0000 Subject: [PATCH] Bug 15344: Remove unucessary call to GetMemberDetails This subroutine does a lot a processing and should only be called when necessary. In the get_template_and_user subroutine (so called from any pages of Koha), it is call to pass the branchcode, title, firstname, surname and borrowernumber values for the logged in user. This subroutine calls GetMemberAccountRecords which retrieve the items infos for all accountlines entries of the logged in user. On members/members.pl, let's say you have 74 entries in the accountlines tables, the page will execute 115 SELECT instead of 35 if you don't have any accountlines entries. With this patch, the number of SELECT is always 31. To test this patch you should have technical skills to know what to do. Note that USER_INFO was an array of... 1 element. Now it's a hashref. --- C4/Auth.pm | 10 +++++----- admin/aqbudgets.pl | 2 +- admin/aqplan.pl | 6 +++--- koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc | 10 +++++----- .../intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt | 2 +- .../intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt | 6 +----- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt | 2 +- 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 8c6d747..5247ede 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -208,9 +208,10 @@ sub get_template_and_user { # It's possible for $user to be the borrowernumber if they don't have a # userid defined (and are logging in through some other method, such # as SSL certs against an email address) + my $borrower; $borrowernumber = getborrowernumber($user) if defined($user); if ( !defined($borrowernumber) && defined($user) ) { - my $borrower = C4::Members::GetMember( borrowernumber => $user ); + $borrower = C4::Members::GetMember( borrowernumber => $user ); if ($borrower) { $borrowernumber = $user; @@ -218,6 +219,8 @@ sub get_template_and_user { # to do it. $user = $borrower->{firstname} . ' ' . $borrower->{surname}; } + } else { + $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); } # user info @@ -244,10 +247,7 @@ sub get_template_and_user { ); } - my ($borr) = C4::Members::GetMemberDetails($borrowernumber); - my @bordat; - $bordat[0] = $borr; - $template->param( "USER_INFO" => \@bordat ); + $template->param( "USER_INFO" => $borrower ); my $all_perms = get_all_subpermissions(); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 2d85fdc..d78ba12 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -88,7 +88,7 @@ if ( $budget_period_id ) { # ------- get periods stuff ------------------ # USED FOR PERMISSION COMPARISON LATER -my $borrower_id = $template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'}; +my $borrower_id = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'}; my $user = GetMemberDetails($borrower_id); my $user_branchcode = $user->{'branchcode'}; diff --git a/admin/aqplan.pl b/admin/aqplan.pl index d0b11a2..f1bf496 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -82,8 +82,8 @@ $template->param( # ------- get periods stuff ------------------ -my $borrower_id = $template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'}; -my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}[0]->{'branchcode'}; +my $borrower_id = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'}; +my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}->{'branchcode'}; my $periods; my $authcat = $input->param('authcat'); @@ -109,7 +109,7 @@ my $op = $input->param("op"); my $budget_branchcode; -my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}[0]->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'}:'' ); +my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' ); # build categories list my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' "); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 443c022..6ffaf62 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -601,7 +601,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr $( sel ).on( event, function (e) { e.preventDefault(); handler( e, Preferences.user[pref] ); - Preferences.Save( [% USER_INFO.0.borrowernumber %] ); + Preferences.Save( [% USER_INFO.borrowernumber %] ); showPreference(pref); } ); } @@ -626,7 +626,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr $( document ).on( 'change', 'input.search-toggle-server', function() { var server_id = $( this ).closest('li').data('server-id'); Preferences.user.selected_search_targets[server_id] = this.checked; - Preferences.Save( [% USER_INFO.0.borrowernumber %] ); + Preferences.Save( [% USER_INFO.borrowernumber %] ); } ); break; } @@ -664,7 +664,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr delete Preferences.user.macros[name]; } - Preferences.Save( [% USER_INFO.0.borrowernumber %] ); + Preferences.Save( [% USER_INFO.borrowernumber %] ); } function showSavedMacros( macros ) { @@ -966,7 +966,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr $( '#switch-editor' ).click( function() { if ( !confirm( _("Any changes will not be saved. Continue?") ) ) return; - $.cookie( 'catalogue_editor_[% USER_INFO.0.borrowernumber %]', 'basic', { expires: 365, path: '/' } ); + $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'basic', { expires: 365, path: '/' } ); if ( state.backend == 'catalog' ) { window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + state.recordID; @@ -1072,7 +1072,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr } ); // Start editor - Preferences.Load( [% USER_INFO.0.borrowernumber || 0 %] ); + Preferences.Load( [% USER_INFO.borrowernumber || 0 %] ); displayPreferences(editor); makeAuthorisedValueWidgets( '' ); Search.Init( { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 542d8cb..2b6b327 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -111,7 +111,7 @@ if ( !confirm( breedingid ? _("This record cannot be transferred to the advanced editor. Continue?") : _("Any changes will not be saved. Continue?") ) ) return false; - $.cookie( 'catalogue_editor_[% USER_INFO.0.borrowernumber %]', 'advanced', { expires: 365, path: '/' } ); + $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'advanced', { expires: 365, path: '/' } ); var biblionumber = [% biblionumber || "null" %]; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt index 9ef3543..290b386 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -25,7 +25,7 @@ }); $("#useadvanced").click(function(){ - $.cookie( 'catalogue_editor_[% USER_INFO.0.borrowernumber %]', 'advanced', { expires: 365, path: '/' } ); + $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'advanced', { expires: 365, path: '/' } ); return true; }); }); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc index 20ff3f8..5a2e011 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc @@ -95,7 +95,7 @@ [% END %] [% END %] [% IF ( loggedinusername ) %] -
  • +
  • [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt index ee0f205..4e4f832 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt @@ -10,7 +10,7 @@