From 87f84046681b11198a5d3e8502ae94e96915cb61 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 3 Mar 2022 14:40:20 +0000 Subject: [PATCH] Bug 29523: Cache the restricted branches list This patch introduces a very localised cache of the restricted branches list in the logged in patron object. --- Koha/Patron.pm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index b9767d56ca..b1dd0a4c0a 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1454,13 +1454,8 @@ sub can_see_patrons_from { $can = 1; } elsif ( $self->has_permission( { borrowers => 'view_borrower_infos_from_any_libraries' } ) ) { $can = 1; - } elsif ( my $library_groups = $self->library->library_groups ) { - while ( my $library_group = $library_groups->next ) { - if ( $library_group->parent->has_child( $branchcode ) ) { - $can = 1; - last; - } - } + } elsif ( my @branches = $self->libraries_where_can_see_patrons ) { + $can = any { $_ eq $branchcode } @branches; } return $can; } @@ -1494,7 +1489,7 @@ sub can_log_into { =head3 libraries_where_can_see_patrons -my $libraries = $patron-libraries_where_can_see_patrons; +my $libraries = $patron->libraries_where_can_see_patrons; Return the list of branchcodes(!) of libraries the patron is allowed to see other patron's infos. The branchcodes are arbitrarily returned sorted. @@ -1506,6 +1501,8 @@ An empty array means no restriction, the patron can see patron's infos from any sub libraries_where_can_see_patrons { my ( $self ) = @_; + return $self->{_restricted_branchcodes} if exists($self->{_restricted_branchcodes}); + my $userenv = C4::Context->userenv; return () unless $userenv; # For tests, but userenv should be defined in tests... @@ -1539,7 +1536,9 @@ sub libraries_where_can_see_patrons { @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes; @restricted_branchcodes = uniq(@restricted_branchcodes); @restricted_branchcodes = sort(@restricted_branchcodes); - return @restricted_branchcodes; + + $self->{_restricted_branchcodes} = \@restricted_branchcodes; + return @{$self->{_restricted_branchcodes}}; } =head3 has_permission -- 2.20.1