From 9f7e2c4c794495f2a32410fd373cc313e0b0d4cf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 Nov 2017 15:16:51 +0100 Subject: [statistics&syslog] Fix possible cron delete query overflow --- modules-available/statistics/hooks/cron.inc.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index 94c65248..575ab6ba 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -1,8 +1,5 @@ 86400 * 190"); -Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365"); - function logstats() { $NOW = time(); $cutoff = $NOW - 86400 * 30; @@ -15,4 +12,18 @@ function logstats() { 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], )); } + logstats(); + +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE statistic"); + } +} +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - 86400 * 365) > lastseen"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE machine"); + } +} -- cgit v1.2.3-55-g7522