[ADDED] Flush statistics_users entries after 7 days default
This commit is contained in:
parent
87bdd61fe9
commit
226d2c8b54
@ -65,7 +65,7 @@ $status = 'OK';
|
|||||||
$message = '';
|
$message = '';
|
||||||
$affected = $share->purgeArchive();
|
$affected = $share->purgeArchive();
|
||||||
if ($affected === false) {
|
if ($affected === false) {
|
||||||
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
|
$message = 'Failed to delete shares: ' . $share->getCronError();
|
||||||
$status = 'ERROR';
|
$status = 'ERROR';
|
||||||
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
|
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
|
||||||
} else {
|
} else {
|
||||||
@ -73,6 +73,19 @@ if ($affected === false) {
|
|||||||
}
|
}
|
||||||
$log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message));
|
$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
|
// Cron cleanup and monitoring
|
||||||
require_once('cron_end.inc.php');
|
require_once('cron_end.inc.php');
|
||||||
|
|||||||
@ -927,6 +927,17 @@ class Statistics extends Base {
|
|||||||
return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
|
return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
|
||||||
return $this->sqlError();
|
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();
|
$statistics = new Statistics();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user