From c692ab052ac7edba815bdadb278e47b9d056e234 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 8 Sep 2017 17:20:38 +0200 Subject: [PATCH] Bug 19279: performance of linked items in search When catalog has fields 773 (461 in UNIMARC), those linked items are fetched for display in search results. Look like the code could be more performant by replacing item search by $9 with direct call with GetMarcItem(). Test plan : - Get a record A with a lot of items - Create a new record B - Create a linked items from B to A with a field 773 (461 in UNIMARC) : biblionumber in $0 and itemnumber in $9 - Display B record details => Compare execution times with and without patch Signed-off-by: Hugo Agud Signed-off-by: Kyle M Hall --- C4/Search.pm | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 65f514498f..7d2b3a01ff 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2013,18 +2013,11 @@ sub searchResults { my $hostbiblionumber = $hostfield->subfield("0"); my $linkeditemnumber = $hostfield->subfield("9"); if( $hostbiblionumber ) { - my $hostbiblio = GetMarcBiblio({ - biblionumber => $hostbiblionumber, - embed_items => 1 }); - my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber' ); - if( $hostbiblio ) { - my @hostitems = $hostbiblio->field($itemfield); - foreach my $hostitem (@hostitems){ - if ($hostitem->subfield("9") eq $linkeditemnumber){ - my $linkeditem =$hostitem; - # append linked items if they exist - push @fields, $linkeditem if $linkeditem; - } + my $linkeditemmarc = C4::Items::GetMarcItem( $hostbiblionumber, $linkeditemnumber ); + if ($linkeditemmarc) { + my $linkeditemfield = $linkeditemmarc->field($itemtag); + if ($linkeditemfield) { + push( @fields, $linkeditemfield ); } } } -- 2.17.1