From c46a14af5388283ca5fdc50516e422fc5dc2b270 Mon Sep 17 00:00:00 2001 From: rj-taylor <57951629+rj-taylor@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:57:56 -0500 Subject: [PATCH] Prevent syslog table purge from spamming daily.log (#10851) daily.php's syslog purge block writes output for every dbDelete() except for the final one. The deletes are done in blocks of 1000 rows. This can lead to verbose output while the table is purged. This patch saves up all that excitement for a single echo at the end of the operation. It also outputs the total amount of rows deleted. --- daily.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daily.php b/daily.php index 3bf7dab1c8..7597478be5 100644 --- a/daily.php +++ b/daily.php @@ -70,21 +70,24 @@ if ($options['f'] === 'syslog') { if (is_numeric($syslog_purge)) { $rows = (int)dbFetchCell('SELECT MIN(seq) FROM syslog'); + $initial_rows = $rows; while (true) { $limit = dbFetchCell('SELECT seq FROM syslog WHERE seq >= ? ORDER BY seq LIMIT 1000,1', array($rows)); if (empty($limit)) { break; } + # Deletes are done in blocks of 1000 to avoid a single very large operation. if (dbDelete('syslog', 'seq >= ? AND seq < ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)', array($rows, $limit, $syslog_purge)) > 0) { $rows = $limit; - echo "Syslog cleared for entries over $syslog_purge days 1000 limit\n"; } else { break; } } dbDelete('syslog', 'seq >= ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)', array($rows, $syslog_purge)); + $final_rows = $rows - $initial_rows; + echo "Syslog cleared for entries over $syslog_purge days (about $final_rows rows)\n"; } } catch (LockException $e) { echo $e->getMessage() . PHP_EOL;