Bugzilla – Attachment 85904 Details for
Bug 20664
Optimize retrieval of biblio and item data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20664: (follow-up) Switch to Koha objects for retrieving items
Bug-20664-follow-up-Switch-to-Koha-objects-for-ret.patch (text/plain), 4.37 KB, created by
Ere Maijala
on 2019-03-01 14:18:00 UTC
(
hide
)
Description:
Bug 20664: (follow-up) Switch to Koha objects for retrieving items
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2019-03-01 14:18:00 UTC
Size:
4.37 KB
patch
obsolete
>From 3e85f29e89461448c7f134fb02b6893fef85e720 Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Wed, 27 Feb 2019 17:01:35 +0200 >Subject: [PATCH] Bug 20664: (follow-up) Switch to Koha objects for retrieving > items > >--- > C4/Biblio.pm | 24 ++++++++---------------- > C4/Items.pm | 35 ++++++++++++++++------------------- > 2 files changed, 24 insertions(+), 35 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 78d0754a81..36e3678d12 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1075,22 +1075,14 @@ sub GetMarcSubfieldStructure { > sub GetMarcFromKohaField { > my ( $kohafield ) = @_; > return unless $kohafield; >- >- my $cache = Koha::Caches->get_instance(); >- my $cache_key = "MarcFromKohaField-$kohafield"; >- my $cached = $cache->get_from_cache($cache_key); >- if ( !defined $cached ) { >- # The next call uses the Default framework since it is AUTHORITATIVE >- # for all Koha to MARC mappings. >- my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework >- my @retval; >- foreach( @{ $mss->{$kohafield} } ) { >- push @retval, $_->{tagfield}, $_->{tagsubfield}; >- } >- $cached = \@retval; >- $cache->set_in_cache( $cache_key, $cached ); >- } >- return wantarray ? @$cached : ( @$cached ? $cached->[0] : undef ); >+ # The next call uses the Default framework since it is AUTHORITATIVE >+ # for all Koha to MARC mappings. >+ my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework >+ my @retval; >+ foreach( @{ $mss->{$kohafield} } ) { >+ push @retval, $_->{tagfield}, $_->{tagsubfield}; >+ } >+ return wantarray ? @retval : ( @retval ? $retval[0] : undef ); > } > > =head2 GetMarcSubfieldStructureFromKohaField >diff --git a/C4/Items.pm b/C4/Items.pm >index d136561f0e..643731cbc2 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1354,25 +1354,29 @@ Returns an array of MARC::Record objects of the items for the biblio. > sub GetMarcItemFields { > my ( $biblionumber, $itemnumbers, $hidingrules ) = @_; > >- my $item_level_itype = C4::Context->preference('item-level_itypes'); >- # This is so much faster than using Koha::Items->search that it makes sense even if it's ugly. >- my $query = 'SELECT * FROM items WHERE biblionumber = ?'; >+ my $params = { >+ biblionumber => $biblionumber >+ }; > if (@$itemnumbers) { >- $query .= ' AND itemnumber IN (' . join(',', @$itemnumbers) . ')'; >+ my @itemnumberlist; >+ foreach my $itemnumber (@$itemnumbers) { >+ push @itemnumberlist, {itemnumber => $itemnumber}; >+ } >+ $params->{-or} = \@itemnumberlist; > } >- my $sth = C4::Context->dbh->prepare($query); >- $sth->execute($biblionumber); >- my $items = $sth->fetchall_arrayref({}); >- $sth->finish(); >+ my $items = Koha::Items->search($params); > my @item_fields; > my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber'); > >- ITEMLOOP: foreach my $item (@$items) { >+ ITEMLOOP: while ( my $item = $items->next() ) { >+ >+ my $item_unblessed = $item->unblessed; >+ $item_unblessed->{itype} = $item->effective_itemtype() unless $item_unblessed->{itype}; > > # Check hiding rules > if (defined $hidingrules) { > foreach my $field (keys %$hidingrules) { >- my $val = $item->{$field}; >+ my $val = $item_unblessed->{$field}; > $val = '' unless defined $val; > > # If the results matches the values in the hiding rules, skip the item >@@ -1382,17 +1386,10 @@ sub GetMarcItemFields { > } > } > >- # Set correct item type >- if (!$item_level_itype || !$item->{itype}) { >- warn 'item-level_itypes set but no itemtype set for item (' . $item->{itemnumber} . ')' if (!$item->{itype}); >- my $biblioitem = Koha::Biblioitems->find($item->{biblioitemnumber}); >- $item->{itype} = $biblioitem->itemtype(); >- } >- > my $mungeditem = { > map { >- defined($item->{$_}) && $item->{$_} ne '' ? ("items.$_" => $item->{$_}) : () >- } keys %{ $item } >+ defined($item_unblessed->{$_}) && $item_unblessed->{$_} ne '' ? ("items.$_" => $item_unblessed->{$_}) : () >+ } keys %{ $item_unblessed } > }; > my $itemmarc = TransformKohaToMarc($mungeditem); > >-- >2.17.1
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 20664
:
74873
|
75968
|
76045
|
76046
|
76669
|
78868
|
78869
|
78870
|
79225
|
79227
|
79228
|
79229
|
79276
|
79277
|
79278
|
79279
|
84516
|
84517
|
84518
|
84519
|
84520
|
85106
|
85107
|
85108
|
85109
|
85110
|
85776
|
85777
|
85778
|
85779
|
85780
|
85781
|
85898
|
85899
|
85900
|
85901
|
85902
|
85903
|
85904
|
85905
|
86002
|
86003
|
86004
|
86005
|
86006
|
86007
|
86008
|
86009