Bugzilla – Attachment 76660 Details for
Bug 21006
GetMarcBiblio is slow for records with many items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21006: Add GetMarcItems method and refactor GetMarcBiblio
Bug-21006-Add-GetMarcItems-method-and-refactor-Get.patch (text/plain), 3.67 KB, created by
Nick Clemens (kidclamp)
on 2018-07-04 01:27:55 UTC
(
hide
)
Description:
Bug 21006: Add GetMarcItems method and refactor GetMarcBiblio
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2018-07-04 01:27:55 UTC
Size:
3.67 KB
patch
obsolete
>From bc26e6c79ed5caafd530414b1ac79e755a780140 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 27 Jun 2018 02:58:55 +0000 >Subject: [PATCH] Bug 21006: Add GetMarcItems method and refactor GetMarcBiblio > >--- > C4/Biblio.pm | 10 +++------- > C4/Items.pm | 34 ++++++++++++++++++++++++++++++++-- > 2 files changed, 35 insertions(+), 9 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 0c5a917..11c49a4 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1194,6 +1194,7 @@ sub GetMarcBiblio { > > C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, > $biblioitemnumber ); >+ > C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac ) > if ($embeditems); > >@@ -2800,7 +2801,6 @@ sub EmbedItemsInMarcBiblio { > my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); > $sth->execute($biblionumber); > my @item_fields; >- my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); > my @items; > my $opachiddenitems = $opac > && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); >@@ -2816,12 +2816,8 @@ sub EmbedItemsInMarcBiblio { > : (); > # Convert to a hash for quick searching > my %hiddenitems = map { $_ => 1 } @hiddenitems; >- foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { >- next if $hiddenitems{$itemnumber}; >- my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >- push @item_fields, $item_marc->field($itemtag); >- } >- $marc->append_fields(@item_fields); >+ my $item_fields = C4::Items::GetMarcItems( $biblionumber, \@hiddenitems, $itemnumbers ); >+ $marc->append_fields(@$item_fields); > } > > =head1 INTERNAL FUNCTIONS >diff --git a/C4/Items.pm b/C4/Items.pm >index bf464c3..b81898f 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1496,14 +1496,44 @@ sub GetMarcItem { > return Item2Marc($itemrecord,$biblionumber); > > } >+ >+=head2 GetMarcItems >+ >+ my @items_marc = GetMarcItems($biblionumber, \@hiddenitemnumbers, \@itemnumbers); >+ >+Returns array of MARC::Records of the items for the biblio passed in parameter. >+ >+=cut >+ >+sub GetMarcItems { >+ my ( $biblionumber, $hiddenitems, $itemnumbers ) = @_; >+ my $params; >+ $params->{biblionumber} = $biblionumber; >+ $params->{itemnumber} = {'not in' => $hiddenitems} if defined $hiddenitems && scalar @$hiddenitems; >+ $params->{itemnumber} = {'in' => $itemnumbers} if defined $itemnumbers && scalar @$itemnumbers; >+ my $items = Koha::Items->search($params ); >+ return unless $items; >+ >+ # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work. >+ # Also, don't emit a subfield if the underlying field is blank. >+ >+ my $framework = Koha::Biblios->find( $biblionumber)->frameworkcode(); >+ my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber", $framework); >+ my @marc_items; >+ while ( my $this_item = $items->next() ){ >+ push @marc_items, Item2Marc($this_item->unblessed,$biblionumber,$framework)->field($itemtag); >+ } >+ return \@marc_items; >+} >+ > sub Item2Marc { >- my ($itemrecord,$biblionumber)=@_; >+ my ($itemrecord,$biblionumber, $frameworkcode)=@_; > my $mungeditem = { > map { > defined($itemrecord->{$_}) && $itemrecord->{$_} ne '' ? ("items.$_" => $itemrecord->{$_}) : () > } keys %{ $itemrecord } > }; >- my $framework = C4::Biblio::GetFrameworkCode( $biblionumber ); >+ my $framework = $frameworkcode // C4::Biblio::GetFrameworkCode( $biblionumber ); > my $itemmarc = C4::Biblio::TransformKohaToMarc( > $mungeditem, { no_split => 1}, > ); >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21006
:
76475
|
76490
|
76659
| 76660 |
76661