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 | |
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
-rw-r--r-- | modules-available/statistics/hooks/cron.inc.php | 17 | ||||
-rw-r--r-- | modules-available/syslog/hooks/cron.inc.php | 5 |
2 files changed, 18 insertions, 4 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"); + } +} diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php index c796675f..bae882a9 100644 --- a/modules-available/syslog/hooks/cron.inc.php +++ b/modules-available/syslog/hooks/cron.inc.php @@ -1,5 +1,8 @@ <?php if (mt_rand(1, 10) === 1) { - Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 190"); + Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE clientlog"); + } }
\ No newline at end of file |