[Koha-bugs] [Bug 32464] Koha::Item->as_marc_field obsolete option mss

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue May 2 14:38:09 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=32464

--- Comment #15 from Nick Clemens <nick at bywatersolutions.com> ---
(In reply to Jonathan Druart from comment #14)
> (In reply to Nick Clemens from comment #13)
> > See comment 5, please test
> 
> What/how did you test?
> 

Fortunately, I still had the script I used, it seems we have improved things
though, I get much smaller results:
             Rate noPassMSS   passMSS
noPassMSS 14088/s        --      -14%
passMSS   16373/s       16%        --


#!/usr/bin/env perl

use strict;
use warnings;

use Benchmark qw/cmpthese timethese/;
use Koha::Biblios;

my $biblio = Koha::Biblios->find( 25 );
my $record = $biblio->metadata->record;
my @items  = $biblio->items->as_list;

my $record_processor = Koha::RecordProcessor->new({
    filters => ['EmbedItems'],
    options => {
        interface => 'opac',
        items     => \@items
    }
});



cmpthese(
    -10,
    {
        noPassMSS => sub {
            $record_processor->process( $record, 0);
        },
        passMSS => sub {
            $record_processor->process( $record, 1);
        },
    }
);


Diff:
diff --git a/Koha/Filter/MARC/EmbedItems.pm b/Koha/Filter/MARC/EmbedItems.pm
index 2839694ff8..7401c3ebb9 100644
--- a/Koha/Filter/MARC/EmbedItems.pm
+++ b/Koha/Filter/MARC/EmbedItems.pm
@@ -67,6 +67,7 @@ Embed items into the MARC::Record object.
 sub filter {
     my $self   = shift;
     my $record = shift;
+    my $pass_mss = shift;

     return unless defined $record and ref($record) eq 'MARC::Record';

@@ -76,6 +77,8 @@ sub filter {

     my @item_fields;

+    $mss = undef unless $pass_mss;
+
     foreach my $item ( @{$items} ) {
         push @item_fields, $item->as_marc_field( { mss => $mss } );
     }
diff --git a/Koha/Item.pm b/Koha/Item.pm
index 7251a8a094..f4e701bd58 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -939,15 +939,15 @@ with the current mappings configuration.
 =cut

 sub as_marc_field {
-    my ( $self ) = @_;
+    my ( $self, $params ) = @_;

     my ( $itemtag, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField(
"items.itemnumber" );

-    my $tagslib = C4::Biblio::GetMarcStructure( 1,
$self->biblio->frameworkcode, { unsafe => 1 });
+    my $mss = $params->{mss} // C4::Biblio::GetMarcSubfieldStructure( '', {
unsafe => 1 } );

     my @subfields;

-    my $item_field = $tagslib->{$itemtag};
+    my $item_field = $mss->{$itemtag};

     my $more_subfields = $self->additional_attributes->to_hashref;
     foreach my $subfield (
diff --git a/Koha/RecordProcessor.pm b/Koha/RecordProcessor.pm
index ec7cbea0ca..fff2e7810a 100644
--- a/Koha/RecordProcessor.pm
+++ b/Koha/RecordProcessor.pm
@@ -172,12 +172,13 @@ return value will be of the same type.
 sub process {
     my $self = shift;
     my $record = shift || $self->record;
+    my $pass_mss = shift;

     return unless defined $record;

     foreach my $filterobj (@{$self->filters}) {
         next unless $filterobj;
-        $filterobj->filter($record);
+        $filterobj->filter($record, $pass_mss);
     }

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list