Browse Source

Bug 24786: (follow-up) Cache the register_name in the session

This leads to one DB hit less per page load in the staff client when
cash registers are enabled.

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Martin Renvoize 1 year ago
committed by Jonathan Druart
parent
commit
1bc723b33c
  1. 16
      C4/Auth.pm
  2. 21
      C4/Context.pm
  3. 5
      Koha/Template/Plugin/Registers.pm
  4. 6
      circ/set-library.pl
  5. 4
      koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt

16
C4/Auth.pm

@ -38,6 +38,7 @@ use Koha::Checkouts;
use Koha::DateUtils qw(dt_from_string);
use Koha::Library::Groups;
use Koha::Libraries;
use Koha::Cash::Registers;
use Koha::Desks;
use Koha::Patrons;
use Koha::Patron::Consents;
@ -868,7 +869,7 @@ sub checkauth {
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
$session->param('register_id'), $session->param('register_name')
);
C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
@ -1091,7 +1092,7 @@ sub checkauth {
}
my ( $borrowernumber, $firstname, $surname, $userflags,
$branchcode, $branchname, $emailaddress, $desk_id,
$desk_name, $register_id );
$desk_name, $register_id, $register_name );
if ( $return == 1 ) {
my $select = "
@ -1142,6 +1143,8 @@ sub checkauth {
}
if ( $query->param('register_id') ) {
$register_id = $query->param('register_id');
my $register = Koha::Cash::Registers->find($register_id);
$register_name = $register ? $register->name : '';
}
my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) {
@ -1188,6 +1191,7 @@ sub checkauth {
$session->param( 'interface', $type);
$session->param( 'shibboleth', $shibSuccess );
$session->param( 'register_id', $register_id );
$session->param( 'register_name', $register_name );
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
}
$session->param('cas_ticket', $cas_ticket) if $cas_ticket;
@ -1198,7 +1202,7 @@ sub checkauth {
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
$session->param('register_id'), $session->param('register_name')
);
}
@ -1478,7 +1482,7 @@ sub check_api_auth {
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
$session->param('register_id'), $session->param('register_name')
);
my $ip = $session->param('ip');
@ -1642,7 +1646,7 @@ sub check_api_auth {
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
$session->param('register_id'), $session->param('register_name')
);
return ( "ok", $cookie, $sessionID );
} else {
@ -1732,7 +1736,7 @@ sub check_cookie_auth {
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
$session->param('register_id'), $session->param('register_name')
);
my $ip = $session->param('ip');

21
C4/Context.pm

@ -806,7 +806,7 @@ sub userenv {
$userbranch, $branchname, $userflags,
$emailaddress, $shibboleth
$desk_id, $desk_name,
$register_id);
$register_id, $register_name);
Establish a hash of user environment variables.
@ -817,7 +817,7 @@ set_userenv is called in Auth.pm
#'
sub set_userenv {
shift @_;
my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth, $desk_id, $desk_name, $register_id)=
my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth, $desk_id, $desk_name, $register_id, $register_name)=
map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here
@_;
my $var=$context->{"activeuser"} || '';
@ -829,14 +829,15 @@ sub set_userenv {
"surname" => $usersurname,
#possibly a law problem
"branch" => $userbranch,
"branchname" => $branchname,
"flags" => $userflags,
"emailaddress" => $emailaddress,
"shibboleth" => $shibboleth,
"desk_id" => $desk_id,
"desk_name" => $desk_name,
"register_id" => $register_id,
"branch" => $userbranch,
"branchname" => $branchname,
"flags" => $userflags,
"emailaddress" => $emailaddress,
"shibboleth" => $shibboleth,
"desk_id" => $desk_id,
"desk_name" => $desk_name,
"register_id" => $register_id,
"register_name" => $register_name
};
$context->{userenv}->{$var} = $cell;
return $cell;

5
Koha/Template/Plugin/Registers.pm

@ -37,8 +37,9 @@ sub session_register_id {
sub session_register_name {
my ($self) = @_;
my $register = Koha::Cash::Registers->find($self->session_register_id);
return $register ? $register->name : '';
return C4::Context->userenv
? C4::Context->userenv->{'register_name'}
: '';
}
=head2

6
circ/set-library.pl

@ -81,14 +81,14 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) {
if ( defined($userenv_register_id)
&& ( $userenv_register_id ne $register_id ) )
{
my $old_register_name = C4::Context->userenv->{'register_name'} || '';
my $register = Koha::Cash::Registers->find($register_id);
$template->param(LoginRegisterID => $register_id); # update template for new register
$template->param(LoginRegisterName => $register ? $register->name : ''); # update template for new register
$session->param( 'register_id', $register_id );
$session->param( 'register_name', $register ? $register->name : '' );
push @updated,
{
updated_register => 1,
new_register => $register ? $register->name : ''
old_register => $old_register_name
};
}
$session->flush();

4
koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt

@ -45,14 +45,14 @@
Updated:<ul>
[% FOREACH update IN updated %]
[% IF ( update.updated_branch || update.updated_desk || update.updated_register ) %]
[% IF ( updated.updated.branch ) %]
[% IF ( updated.updated_branch ) %]
<li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.new_branch or "?" | html %]</li>
[% END %]
[% IF ( update.updated_desk ) %]
<li>Desk: [% update.old_desk or "?" | html %] &rArr; [% LoginDeskname or "?" | html %]</li>
[% END %]
[% IF ( updated.updated_register ) %]
<li>Register: [% updated.new_register | html %]</li>
<li>Register: [% updated.old_register or "?" | html %] &rArr; [% Registers.session_register_name or "?" | html %]</li>
[% END %]
[% ELSE %]
<li>ERROR - unknown</li>

Loading…
Cancel
Save