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 <david@davidnind.com>
Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Kyle M Hall 2026-07-16 14:23:44 -04:00 committed by Pedro Amorim
parent 53524b4824
commit 6d30ead414
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
3 changed files with 4 additions and 3 deletions

View File

@ -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,

View File

@ -599,7 +599,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 } );

View File

@ -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