Bug 33739: Only trigger indexing on last item modification at ModItemTransfer

This patch makes ModItemTransfer trigger record indexing only on the
last call (in $transfer->transit). And extra parameter is added to
->transit to effectively honour the ModItemTransfer parameter.

I wanted to mention that bug 31212 highlighted an existing issue, not
catched by the current tests before its inclussion, because of the DT truncation
taking place.

To test:
1. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/SearchEngine/Indexer.t
=> FAIL: Indexing is requested twice, should only be once
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass! Indexing is requested only once!
4. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2023-05-15 12:07:09 -03:00 committed by Jonathan Druart
parent 434a73b0e6
commit 25f8581c0d
2 changed files with 10 additions and 5 deletions

View file

@ -380,10 +380,10 @@ sub ModItemTransfer {
$item->holdingbranch($frombranch)->store(
{
log_action => 0,
skip_record_index => $params->{skip_record_index}
skip_record_index => 1, # avoid indexing duplication, let ->transit handle it
}
);
$transfer->transit;
$transfer->transit({ skip_record_index => $params->{skip_record_index} });
}
return;

View file

@ -80,14 +80,19 @@ sub to_library {
=head3 transit
Set the transfer as in transit by updating the datesent time.
$transfer->transit({ [ skip_record_index => 0|1 ] });
Set the transfer as in transit by updating the I<datesent> time.
Also, update date last seen and ensure item holdingbranch is correctly set.
An optional I<skip_record_index> parameter can be passed to avoid triggering
reindex.
=cut
sub transit {
my ($self) = @_;
my ($self, $params) = @_;
# Throw exception if item is still checked out
Koha::Exceptions::Item::Transfer::OnLoan->throw() if ( $self->item->checkout );
@ -107,7 +112,7 @@ sub transit {
}
)->store;
ModDateLastSeen( $self->item->itemnumber );
ModDateLastSeen( $self->item->itemnumber, undef, { skip_record_index => $params->{skip_record_index} } );
return $self;
}