From 217cfc287eb0087726eaae43a52dd5a7018dc7e5 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 6 Dec 2022 10:39:14 +0000 Subject: [PATCH] Bug 32013: Autorenewal batch indexing The automatic_renewals.pl cron script currently loops through items for automatic renewal and calls the indexer for each one individually. skip_record_index has now been added as a parameter to the AddRenewal function to skip the indexing process. The item numbers are now added to an array and then the indexer is called once from within automatic_renewals.pl and passed the array to queue one indexing job instead of multiple jobs. Test plan: 1) AddRenewal uses Koha::Items->store() to trigger the indexing process. Run prove -vv t/db_dependent/Koha/SearchEngine/Indexer.t and check tests 5,6,29,30. These tests prove whether passing skip_record_index to store() triggers or skips the indexing process. All four tests should pass to show that skip_index_records can prevent the indexing being triggered. 2) Add multiple renewals that are able to be autorenewed and run the automatic_renewals.pl script. There should be multiple items queued in zebraqueue. 3) Apply patch and try again 4) There should now only be one job queued in zebraqueue Mentored-by: Martin Renvoize Signed-off-by: Nick Clemens --- C4/Circulation.pm | 6 +++++- misc/cronjobs/automatic_renewals.pl | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 336ce9490a1..373acffc9a3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3029,6 +3029,9 @@ C<$seen> is a boolean flag indicating if the item was seen or not during the ren informs the incrementing of the unseen_renewals column. If this flag is not supplied, we fallback to a true value +C<$skip_record_index> is an optional boolean flag to indicate whether queuing the search indexing +should be skipped for this renewal. + =cut sub AddRenewal { @@ -3039,6 +3042,7 @@ sub AddRenewal { my $lastreneweddate = shift || dt_from_string(); my $skipfinecalc = shift; my $seen = shift; + my $skip_record_index = shift; # Fallback on a 'seen' renewal $seen = defined $seen && $seen == 0 ? 0 : 1; @@ -3131,7 +3135,7 @@ sub AddRenewal { $renews = ( $item_object->renewals || 0 ) + 1; $item_object->renewals($renews); $item_object->onloan($datedue); - $item_object->store({ log_action => 0 }); + $item_object->store({ log_action => 0, skip_record_index => $skip_record_index }); # Charge a new rental fee, if applicable my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 4884eee2f34..bf048c09d01 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -148,6 +148,7 @@ print "found " . $auto_renews->count . " auto renewals\n" if $verbose; my $renew_digest = {}; my %report; +my @item_renewal_ids; while ( my $auto_renew = $auto_renews->next ) { print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose; @@ -180,7 +181,8 @@ while ( my $auto_renew = $auto_renews->next ) { $auto_renew->issue_id, $auto_renew->borrowernumber, $auto_renew->itemnumber, $confirm ? 'will' : 'would'; } if ($confirm){ - my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode, undef, undef, undef, 0 ); + my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode, undef, undef, undef, 0, 1 ); + push @item_renewal_ids, $auto_renew->itemnumber; $auto_renew->auto_renew_error(undef)->store; } push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew @@ -226,6 +228,11 @@ while ( my $auto_renew = $auto_renews->next ) { } +if( @item_renewal_ids ){ + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( \@item_renewal_ids, "specialUpdate", "biblioserver" ); +} + if ( $send_notices && $confirm ) { for my $borrowernumber ( keys %report ) { my $patron = Koha::Patrons->find($borrowernumber); -- 2.39.0