From cb77e8938939f8e1f5ac489bd1a1313c3e518e22 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 d39dd7789d..05ce1145a4 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1621,13 +1621,8 @@ sub can_see_things_from { $can = 1; } elsif ( $self->has_permission( { $permission => $subpermission } ) ) { $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; } @@ -1678,6 +1673,8 @@ sub libraries_where_can_see_things { my $subpermission = $params->{subpermission}; my $group_feature = $params->{group_feature}; + 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... @@ -1704,14 +1701,16 @@ sub libraries_where_can_see_things { } } - @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes; + @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes; } } @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.40.1