Bug 41444 - Fetch transfers directly for search results
Summary: Fetch transfers directly for search results
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Nick Clemens (kidclamp)
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-12-12 20:18 UTC by Nick Clemens (kidclamp)
Modified: 2025-12-17 15:47 UTC (History)
1 user (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 41444: Search for transfers directly (2.03 KB, patch)
2025-12-12 20:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 41444: Search for transfers directly (2.08 KB, patch)
2025-12-13 00:26 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens (kidclamp) 2025-12-12 20:18:12 UTC
When processing items for display in search Results we fetch the item object and call get_transfers

When maxItemsInSearchResults is raised to a higher number, say 50, common in consortia to display correct info for many branches this can have a large impact on search speed.

Ultimately, perhaps, we should index the transfer status, but it seems to benefit us to fetch the transfers directly here as we don't use the object for anything else at this point in the code.
Comment 1 Nick Clemens (kidclamp) 2025-12-12 20:23:05 UTC
Created attachment 190469 [details] [review]
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
Comment 2 David Nind 2025-12-13 00:26:34 UTC
Created attachment 190474 [details] [review]
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>
Comment 3 Nick Clemens (kidclamp) 2025-12-16 13:27:33 UTC
Adding a mention that this syspref controls how many items are checked and should be raised as well during testing MaxSearchResultsItemsPerRecordStatusCheck