From 9bea5e8992170acb7c2aaf7fb90bcece7689e2a3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 4 Jun 2024 19:15:07 +0100 Subject: [PATCH] Bug 34027: (QA follow-up) Slight logic improvement This patch updates the loop to optimize the limit handling Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- misc/cronjobs/cleanup_database.pl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index f31167fdd41..7659d8e1b69 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -412,7 +412,7 @@ if ($pLogs) { DELETE FROM action_logs WHERE timestamp < date_sub(curdate(), INTERVAL ? DAY) }; - my @query_params = (); + my @query_params = ($pLogs); if (@preserve_logs) { $log_query .= " AND module NOT IN (" . join( ',', ('?') x @preserve_logs ) . ")"; push @query_params, @preserve_logs; @@ -432,16 +432,14 @@ if ($pLogs) { $sth = $dbh->prepare($log_query); if ($confirm) { if ($logs_batch) { - my $counter = 0; - my $rows = 0; - while ( $counter <= $rows ) { - $sth->execute( $pLogs, @query_params ) or die $dbh->errstr; - sleep 3; - $rows += $sth->rows; - $counter += $logs_batch; - } + my $rows_deleted = 0; + do { + $sth->execute(@query_params) or die $dbh->errstr; + $rows_deleted = $sth->rows; + sleep 3; # Adjust sleep time as needed + } while ( $rows_deleted == $logs_batch ); } else { - $sth->execute( $pLogs, @query_params ) or die $dbh->errstr; + $sth->execute(@query_params) or die $dbh->errstr; } } print "Done with purging action_logs.\n" if $verbose; -- 2.39.5