diff options
author | Simon Rettberg | 2017-11-15 15:16:51 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-15 15:16:51 +0100 |
commit | 9f7e2c4c794495f2a32410fd373cc313e0b0d4cf (patch) | |
tree | c81fa0c81ace880a9ae0801a0a647f867f3607e0 /modules-available/statistics/hooks/cron.inc.php | |
parent | [dozmod] Improve location & exam mode detection (diff) | |
download | slx-admin-9f7e2c4c794495f2a32410fd373cc313e0b0d4cf.tar.gz slx-admin-9f7e2c4c794495f2a32410fd373cc313e0b0d4cf.tar.xz slx-admin-9f7e2c4c794495f2a32410fd373cc313e0b0d4cf.zip |
[statistics&syslog] Fix possible cron delete query overflow
Diffstat (limited to 'modules-available/statistics/hooks/cron.inc.php')
-rw-r--r-- | modules-available/statistics/hooks/cron.inc.php | 17 |
1 files changed, 14 insertions, 3 deletions
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 @@ <?php -Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - dateline) > 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"); + } +} |