From c3e639023afadb68f68fcd8359c7d0d416e45cb2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Apr 2022 13:20:12 +0200 Subject: [PATCH] Bug 30460: Make BatchDeleteBiblio update the index in one request No need to send 1 indexation request per item + 1 per biblio. Test plan: Confirm that the batch biblio deletion tool still works correctly --- Koha/BackgroundJob/BatchDeleteBiblio.pm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm index efd9af2bf4f..2f75bcf9b38 100644 --- a/Koha/BackgroundJob/BatchDeleteBiblio.pm +++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm @@ -3,9 +3,12 @@ package Koha::BackgroundJob::BatchDeleteBiblio; use Modern::Perl; use JSON qw( encode_json decode_json ); -use Koha::DateUtils qw( dt_from_string ); use C4::Biblio; +use Koha::DateUtils qw( dt_from_string ); +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; + use base 'Koha::BackgroundJob'; =head1 NAME @@ -107,7 +110,7 @@ sub process { # Delete items my $items = Koha::Items->search({ biblionumber => $biblionumber }); while ( my $item = $items->next ) { - my $deleted = $item->safe_delete; + my $deleted = $item->safe_delete({ skip_record_index => 1 }); unless ( $deleted ) { push @messages, { type => 'error', @@ -124,7 +127,7 @@ sub process { # Finally, delete the biblio my $error = eval { - C4::Biblio::DelBiblio( $biblionumber ); + C4::Biblio::DelBiblio( $biblionumber, { skip_record_index => 1 } ); }; if ( $error or $@ ) { push @messages, { @@ -148,6 +151,15 @@ sub process { $self->progress( ++$job_progress )->store; } + my @deleted_biblionumbers = + map { $_->{code} eq 'biblio_deleted' ? $_->{biblionumber} : () } + @messages; + + if ( @deleted_biblionumbers ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( \@deleted_biblionumbers, "recordDelete", "biblioserver" ); + } + my $job_data = decode_json $self->data; $job_data->{messages} = \@messages; $job_data->{report} = $report; -- 2.25.1