Skip to content

Commit 226d2c8

Browse files
committed
[ADDED] Flush statistics_users entries after 7 days default
1 parent 87bdd61 commit 226d2c8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

cronjobs/tables_cleanup.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,27 @@
6565
$message = '';
6666
$affected = $share->purgeArchive();
6767
if ($affected === false) {
68-
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
68+
$message = 'Failed to delete shares: ' . $share->getCronError();
6969
$status = 'ERROR';
7070
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
7171
} else {
7272
$affected == 0 ? $message = 'No shares deleted' : $message = 'Deleted old shares';
7373
}
7474
$log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message));
7575

76+
// Clenaup shares archive
77+
$start = microtime(true);
78+
$status = 'OK';
79+
$message = '';
80+
$affected = $statistics->purgeUserStats();
81+
if ($affected === false) {
82+
$message = 'Failed to delete entries: ' . $statistics->getCronError();
83+
$status = 'ERROR';
84+
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
85+
} else {
86+
$affected == 0 ? $message = 'No entries deleted' : $message = 'Deleted old entries';
87+
}
88+
$log->logInfo(sprintf($strLogMask, 'purgeUserStats', $affected, number_format(microtime(true) - $start, 3), $status, $message));
7689

7790
// Cron cleanup and monitoring
7891
require_once('cron_end.inc.php');

include/classes/statistics.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,17 @@ public function getCountAllActiveUsers($interval=120) {
927927
return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
928928
return $this->sqlError();
929929
}
930+
931+
/**
932+
* Purge older entries from our statistics_users table
933+
**/
934+
public function purgeUserStats($days = 7) {
935+
// Fallbacks if unset
936+
$stmt = $this->mysqli->prepare("DELETE FROM " . $this->getUserStatsTableName() . " WHERE FROM_UNIXTIME(timestamp) <= DATE_SUB(NOW(), INTERVAL ? DAY)");
937+
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute())
938+
return $stmt->affected_rows;
939+
return $this->sqlError();
940+
}
930941
}
931942

932943
$statistics = new Statistics();

0 commit comments

Comments
 (0)