Bug 41444: Search for transfers directly

This patch removes a fetch of the item object followed but get_transfer to simply search the
transfers by itemnumber and status

To test:
1 - Add many items to your records
    https://github.com/kidclamp/handy-koha-script/blob/main/randitems.pl
    NOTE: this script makes a lot of items withdrawn or damaged, undo that for more dramatic difference
    UPDATE items SET withdrawn=0,damaged=0
    perl misc/search_tools/rebuild_elasticsearch -v
2 - Set Koha system preferences to display more results and check more items:
    maxItemsInSearchResults 60
    numSearchResults 50
3 - Do a search, several times, note the time it takes
4 - Apply patch, restart all
5 - Repeat search several times, note the time it takes
6 - Confirm it is better after the patch

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2025-12-12 20:18:26 +00:00 committed by Laura Escamilla
parent bfd33ed339
commit 5d62b4f614
No known key found for this signature in database
GPG Key ID: 6B1D9CA1AF817BC3
1 changed files with 4 additions and 2 deletions

View File

@ -1979,8 +1979,10 @@ sub searchResults {
# the in transit status count as unavailable for search limiting,
# should map transit status to record indexed in Zebra.
my $item_object = Koha::Items->find( $item->{itemnumber} );
my $transfer = defined($item_object) ? $item_object->get_transfer : undef;
my $transfer = Koha::Item::Transfers->search(
{ itemnumber => $item->{itemnumber}, datearrived => undef, datecancelled => undef },
{ order_by => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
)->next;
( $transfertwhen, $transfertfrom, $transfertto ) = defined($transfer)
? (
$transfer->datesent, $transfer->frombranch,