From 18f71c897ccd08a5fd2c5e7aef1e8db7421f8fa6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 11 May 2020 15:36:53 -0300 Subject: [PATCH] Bug 25457: Make ViewPolicy cache MARC frameworks This patch implements an implicit cache of the calculated MARC subfield structures on each use of the filter. Moreover, if different frameworks are set between calls (using $processor->options) all of them are cached. To test: 1. Apply the tests patch 2. Run: $ kshell k$ prove t/db_dependent/Filter_MARC_ViewPolicy.t => FAIL: The ViewPolicy filter doesn't cache anything 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/Filter/MARC/ViewPolicy.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Koha/Filter/MARC/ViewPolicy.pm b/Koha/Filter/MARC/ViewPolicy.pm index a963e3f129..4d7adfdf67 100644 --- a/Koha/Filter/MARC/ViewPolicy.pm +++ b/Koha/Filter/MARC/ViewPolicy.pm @@ -86,7 +86,11 @@ sub filter { my $result = $current_record; my $hide = _should_hide_on_interface(); - my $marcsubfieldstructure = GetMarcStructure( 0, $frameworkcode, { unsafe => 1 } ); + unless ( exists $self->{_cached_frameworks}->{$frameworkcode} ) { + $self->{_cached_frameworks}->{$frameworkcode} = GetMarcStructure( 0, $frameworkcode, { unsafe => 1 } ); + } + + my $marcsubfieldstructure = $self->{_cached_frameworks}->{$frameworkcode}; #if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { # LDR field is excluded from $current_record->fields(). -- 2.26.2