From b9156c1febd26e6da0edfb0d2910fd834230877d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 16 Jul 2026 14:23:44 -0400 Subject: [PATCH] Bug 43103: Switch OR chains to INs for batch item modification and patron deletion Three searches pass large ID lists: * Koha::BackgroundJob::BatchUpdateItem passes every itemnumber of the batch, and batch item modifications can cover tens of thousands of items * Koha::Items::batch_update does the same with the modified itemnumbers when collecting biblionumbers for reindexing * Koha::Patrons::filter_by_safe_to_delete does it with the borrowernumbers found safe to delete ( unlikely to approach the same numbers as items/bibs, but still good to fix ) This patch switches all three to IN. The lists are still passed as values, but the query stays a flat IN list the optimizer handles well instead of a chain of ORs that can't be optimized. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Items/BatchUpdate.t 3) prove t/db_dependent/Koha/Patrons.t 4) Note all tests pass! Signed-off-by: David Nind Signed-off-by: Emily Lamancusa Signed-off-by: Lucas Gass --- Koha/BackgroundJob/BatchUpdateItem.pm | 2 +- Koha/Items.pm | 3 ++- Koha/Patrons.pm | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob/BatchUpdateItem.pm b/Koha/BackgroundJob/BatchUpdateItem.pm index 71dd00ee05..48354836fd 100644 --- a/Koha/BackgroundJob/BatchUpdateItem.pm +++ b/Koha/BackgroundJob/BatchUpdateItem.pm @@ -104,7 +104,7 @@ sub process { }; try { - my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update( + my ($results) = Koha::Items->search( { itemnumber => { -in => \@record_ids } } )->batch_update( { regex_mod => $regex_mod, new_values => $new_values, diff --git a/Koha/Items.pm b/Koha/Items.pm index adbdd6fc20..74ec56b7ce 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -600,7 +600,8 @@ sub batch_update { if (@modified_itemnumbers) { my @biblionumbers = - uniq( Koha::Items->search( { itemnumber => \@modified_itemnumbers } )->get_column('biblionumber') ); + uniq( + Koha::Items->search( { itemnumber => { -in => \@modified_itemnumbers } } )->get_column('biblionumber') ); if (@biblionumbers) { my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 425893e8d4..34a42a501a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -716,7 +716,7 @@ sub filter_by_safe_to_delete { push @ids, $patron->borrowernumber if $patron->safe_to_delete; } - return Koha::Patrons->search( { borrowernumber => \@ids } ); + return Koha::Patrons->search( { borrowernumber => { -in => \@ids } } ); } =head3 extended_attributes_config