From cb01c54e23a38a2d5583247b521bbda15e27788c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 11 Sep 2020 15:23:02 +0000 Subject: [PATCH] Bug 25375: (QA follow-up) Count available items rather than iterating MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Nick Clemens Signed-off-by: Joonas Kylmälä Signed-off-by: Tomas Cohen Arazi (cherry picked from commit d9cb39e57d1e5c979c605e48493ee5f40df3dac4) Signed-off-by: Lucas Gass (cherry picked from commit 4bdaf6b2d1704f858106b48d445d629942000f64) Signed-off-by: Arthur Suzuki --- Koha/SearchEngine/Elasticsearch.pm | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 33664d516c..e287530464 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -775,21 +775,16 @@ sub marc_records_to_documents { my ($tag, $code) = C4::Biblio::GetMarcFromKohaField('biblio.biblionumber'); my $field = $record->field($tag); my $biblionumber = $field->is_control_field ? $field->data : $field->subfield($code); - my $biblio = Koha::Biblios->find($biblionumber); - my $items = $biblio->items; - my $available = 0; - while (my $item = $items->next) { - next if $item->onloan; - next if $item->notforloan; - next if $item->withdrawn; - next if $item->itemlost; - next if $item->damaged; - - $available = 1; - last; - } - - $record_document->{available} = $available ? \1 : \0; + my $avail_items = Koha::Items->search({ + biblionumber => $biblionumber, + onloan => undef, + notforloan => 0, + withdrawn => 0, + itemlost => 0, + damaged => 0 + })->count; + + $record_document->{available} = $avail_items ? \1 : \0; } push @record_documents, $record_document; -- 2.39.5