@@ -, +, @@ "unsafe" variant for better performance --- C4/Biblio.pm | 21 ++++++++++++++------- C4/Items.pm | 6 +++++- C4/XSLT.pm | 2 +- Koha/Filter/MARC/ViewPolicy.pm | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -932,7 +932,7 @@ sub GetISBDView { return unless defined $record; my $itemtype = &GetFrameworkCode($biblionumber); my ( $holdingbrtagf, $holdingbrtagsubf ) = &GetMarcFromKohaField( "items.holdingbranch", $itemtype ); - my $tagslib = &GetMarcStructure( 1, $itemtype ); + my $tagslib = &GetMarcStructure( 1, $itemtype, { unsafe => 1 } ); my $ISBD = C4::Context->preference($sysprefname); my $bloc = $ISBD; @@ -1109,22 +1109,28 @@ sub IsMarcStructureInternal { =head2 GetMarcStructure - $res = GetMarcStructure($forlibrarian,$frameworkcode); + $res = GetMarcStructure($forlibrarian, $frameworkcode, [ $params ]); Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones $frameworkcode : the framework code to read +TODO: add 'unsafe' parameter description and a warnings: what kinds of operations +on the directly returned data structure are allowed / forbidden +(autovivification of $tagslib->{$tag}->{$subfield} etc. are OK, +but adding/removing/modifying any scalars in the "leafs" are strictly forbidden) + =cut sub GetMarcStructure { - my ( $forlibrarian, $frameworkcode ) = @_; + my ( $forlibrarian, $frameworkcode, $params ) = @_; $frameworkcode = "" unless $frameworkcode; $forlibrarian = $forlibrarian ? 1 : 0; + my $unsafe = ($params && $params->{unsafe})? 1: 0; my $cache = Koha::Cache->get_instance(); my $cache_key = "MarcStructure-$forlibrarian-$frameworkcode"; - my $cached = $cache->get_from_cache($cache_key); + my $cached = $cache->get_from_cache($cache_key, { unsafe => $unsafe }); return $cached if $cached; my $dbh = C4::Context->dbh; @@ -1937,10 +1943,11 @@ sub GetMarcAuthors { } my ( $mintag, $maxtag, $fields_filter ); - # tagslib useful for UNIMARC author reponsabilities - my $tagslib = - &GetMarcStructure( 1, '' ); # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. + # tagslib useful only for UNIMARC author responsibilities + my $tagslib; if ( $marcflavour eq "UNIMARC" ) { + # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. + $tagslib = GetMarcStructure( 1, '', { unsafe => 1 }); $mintag = "700"; $maxtag = "712"; $fields_filter = '7..'; --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2431,7 +2431,7 @@ sub _get_unlinked_item_subfields { my $original_item_marc = shift; my $frameworkcode = shift; - my $marcstructure = GetMarcStructure(1, $frameworkcode); + my $marcstructure = GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); # assume that this record has only one field, and that that # field contains only the item information @@ -2815,6 +2815,10 @@ sub PrepareItemrecordDisplay { my $dbh = C4::Context->dbh; $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum; my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); + + # it would be perhaps beneficial (?) to call GetMarcStructure with 'unsafe' parameter + # for performance reasons, but $tagslib may be passed to $plugin->build(), and there + # is no way to ensure that this structure is not getting corrupted somewhere in there my $tagslib = &GetMarcStructure( 1, $frameworkcode ); # return nothing if we don't have found an existing framework. --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -68,7 +68,7 @@ Is only used in this module currently. sub transformMARCXML4XSLT { my ($biblionumber, $record) = @_; my $frameworkcode = GetFrameworkCode($biblionumber) || ''; - my $tagslib = &GetMarcStructure(1,$frameworkcode); + my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); my @fields; # FIXME: wish there was a better way to handle exceptions eval { --- a/Koha/Filter/MARC/ViewPolicy.pm +++ a/Koha/Filter/MARC/ViewPolicy.pm @@ -84,7 +84,7 @@ sub filter { my $frameworkcode = $self->{options}->{frameworkcode} // q{}; my $hide = _should_hide_on_interface(); - my $marcsubfieldstructure = GetMarcStructure( 0, $frameworkcode ); + my $marcsubfieldstructure = GetMarcStructure( 0, $frameworkcode, { unsafe => 1 } ); #if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { # LDR field is excluded from $current_record->fields(). --