From 98726d5985ce8079cb1fbf3ebbf65fe76ac0f0c3 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 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f0b053b078..26ff7f03ba 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1431,13 +1431,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; } @@ -1483,6 +1478,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... @@ -1516,7 +1513,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