From 0fe026c6fa46135238f91826778bcbffcb13567b 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 Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 15 +++++++++++---- misc/cronjobs/automatic_renewals.pl | 7 +++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f1851ed283..6bba369114 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3083,6 +3083,9 @@ fallback to a true value C<$automatic> is a boolean flag indicating the renewal was triggered automatically and not by a person ( librarian or patron ) +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 { @@ -3094,6 +3097,7 @@ sub AddRenewal { my $skipfinecalc = shift; my $seen = shift; my $automatic = shift; + my $skip_record_index = shift; # Fallback on a 'seen' renewal $seen = defined $seen && $seen == 0 ? 0 : 1; @@ -3188,7 +3192,7 @@ sub AddRenewal { $renews = ( $item_object->renewals || 0 ) + 1; $item_object->renewals($renews); $item_object->onloan($datedue); - # Don't index as we are in a transaction + # Don't index as we are in a transaction, skip hardcoded here $item_object->store({ log_action => 0, skip_record_index => 1 }); # Charge a new rental fee, if applicable @@ -3274,9 +3278,12 @@ sub AddRenewal { } }); }); - # We index now, after the transaction is committed - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); - $indexer->index_records( $item_object->biblionumber, "specialUpdate", "biblioserver" ); + + unless( $skip_record_index ){ + # We index now, after the transaction is committed + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( $item_object->biblionumber, "specialUpdate", "biblioserver" ); + } return $datedue; } diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 0a843843ab..bf048c09d0 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; @@ -181,6 +182,7 @@ while ( my $auto_renew = $auto_renews->next ) { } if ($confirm){ 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.5