From 86bcd2d55d03a6691bdd5b66b89af56facf27acf Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 22 Jul 2022 14:47:36 +0000 Subject: [PATCH] Bug 31222: Reduce query size for batchMod The object search is currently: Koha::Items->search({ barcode => \@contentlist } Which generate code like: barcode = 1 OR barcode = 2 OR barcode = 3 .... This can get quite large We can reduce the query size by using -in: Koha::Items->search({ barcode => { -in => \@contentlist } } Which generates code like: barcode in ( 1, 2, 3 ) To test: 1 - Apply patch 2 - Perform batch modifications 3 - Confirm nothing has changed --- tools/batchMod.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index e24db19104..a1e2bd476b 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -218,13 +218,13 @@ if ($op eq "show"){ @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist ); @contentlist = uniq @contentlist; # Note: adding lc for case insensitivity - my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@contentlist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; + my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => { -in => \@contentlist } }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @contentlist; @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @contentlist; } elsif ( $filecontent eq 'itemid_file') { @contentlist = uniq @contentlist; - my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => \@contentlist }, { columns => [ 'itemnumber' ] } )->unblessed }; + my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => { -in => \@contentlist } }, { columns => [ 'itemnumber' ] } )->unblessed }; @itemnumbers = grep { exists $itemdata{$_} } @contentlist; @notfounditemnumbers = grep { !exists $itemdata{$_} } @contentlist; } @@ -240,7 +240,7 @@ if ($op eq "show"){ @barcodelist = map { barcodedecode( $_ ) } @barcodelist; # Note: adding lc for case insensitivity - my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; + my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => { -in => \@barcodelist } }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist; @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @barcodelist; } -- 2.30.2