From 226d2c8b54f2d233d90cdd9cbbef71f5d93cd1e2 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 17 Jul 2014 07:41:23 +0200 Subject: [PATCH] [ADDED] Flush statistics_users entries after 7 days default --- cronjobs/tables_cleanup.php | 15 ++++++++++++++- include/classes/statistics.class.php | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cronjobs/tables_cleanup.php b/cronjobs/tables_cleanup.php index 04386133..231de9be 100755 --- a/cronjobs/tables_cleanup.php +++ b/cronjobs/tables_cleanup.php @@ -65,7 +65,7 @@ $status = 'OK'; $message = ''; $affected = $share->purgeArchive(); if ($affected === false) { - $message = 'Failed to delete notifications: ' . $oToken->getCronError(); + $message = 'Failed to delete shares: ' . $share->getCronError(); $status = 'ERROR'; $monitoring->endCronjob($cron_name, 'E0008', 0, false, false); } else { @@ -73,6 +73,19 @@ if ($affected === false) { } $log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message)); +// Clenaup shares archive +$start = microtime(true); +$status = 'OK'; +$message = ''; +$affected = $statistics->purgeUserStats(); +if ($affected === false) { + $message = 'Failed to delete entries: ' . $statistics->getCronError(); + $status = 'ERROR'; + $monitoring->endCronjob($cron_name, 'E0008', 0, false, false); +} else { + $affected == 0 ? $message = 'No entries deleted' : $message = 'Deleted old entries'; +} +$log->logInfo(sprintf($strLogMask, 'purgeUserStats', $affected, number_format(microtime(true) - $start, 3), $status, $message)); // Cron cleanup and monitoring require_once('cron_end.inc.php'); diff --git a/include/classes/statistics.class.php b/include/classes/statistics.class.php index dc4a7901..21623142 100644 --- a/include/classes/statistics.class.php +++ b/include/classes/statistics.class.php @@ -927,6 +927,17 @@ class Statistics extends Base { return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total); return $this->sqlError(); } + + /** + * Purge older entries from our statistics_users table + **/ + public function purgeUserStats($days = 7) { + // Fallbacks if unset + $stmt = $this->mysqli->prepare("DELETE FROM " . $this->getUserStatsTableName() . " WHERE FROM_UNIXTIME(timestamp) <= DATE_SUB(NOW(), INTERVAL ? DAY)"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute()) + return $stmt->affected_rows; + return $this->sqlError(); + } } $statistics = new Statistics();