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 <martin.renvoize@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
04f172d344
commit
0fe026c6fa
2 changed files with 18 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue