From 22e72c997f2bf92054a1cd61e83014462a6159f9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 24 Aug 2020 13:13:17 -0400 Subject: [PATCH] Bug 25958: (QA follow-up) Implement filter in database query instead of in loop --- misc/cronjobs/longoverdue.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index d1bb9cb98f..8aabc76bf9 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/misc/cronjobs/longoverdue.pl @@ -298,6 +298,15 @@ sub bounds { # FIXME - This sql should be inside the API. sub longoverdue_sth { + my ( $params ) = @_; + my $skip_lost_values = $params->{skip_lost_values}; + + my $skip_lost_values_sql = q{}; + if ( @$skip_lost_values ) { + my $values = join( ',', map { qq{'$_'} } @$skip_lost_values ); + $skip_lost_values_sql = "AND itemlost NOT IN ( $values )" + } + my $query = " SELECT items.itemnumber, borrowernumber, date_due, itemlost FROM issues, items @@ -305,6 +314,7 @@ sub longoverdue_sth { AND DATE_SUB(CURDATE(), INTERVAL ? DAY) > date_due AND DATE_SUB(CURDATE(), INTERVAL ? DAY) <= date_due AND itemlost <> ? + $skip_lost_values_sql ORDER BY date_due "; return C4::Context->dbh->prepare($query); @@ -376,7 +386,7 @@ my $i = 0; # FIXME - The item is only marked returned if you supply --charge . # We need a better way to handle this. # -my $sth_items = longoverdue_sth(); +my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values }); foreach my $startrange (sort keys %$lost) { if( my $lostvalue = $lost->{$startrange} ) { @@ -389,10 +399,6 @@ foreach my $startrange (sort keys %$lost) { $sth_items->execute($startrange, $endrange, $lostvalue); $count=0; ITEM: while (my $row=$sth_items->fetchrow_hashref) { - if ( @skip_lost_values ) { - next ITEM if any { $_ eq $row->{itemlost} } @skip_lost_values; - } - if( $filter_borrower_categories ) { my $category = uc Koha::Patrons->find( $row->{borrowernumber} )->categorycode(); next ITEM unless ( $category_to_process{ $category } ); -- 2.24.1 (Apple Git-126)