From 3117a3278c3b6875bb0d8094928dd31841469456 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 dd4f280355b..e1072d56814 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -401,7 +401,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; @@ -421,16 +421,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 (Apple Git-154)