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.
This commit is contained in:
rj-taylor 2019-11-19 17:57:56 -05:00 committed by PipoCanaja
parent 827cc0cce3
commit c46a14af53
1 changed files with 4 additions and 1 deletions

View File

@ -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;