From c8b53012679766f5748f1e7d774cd805280f3da5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 23 Oct 2022 07:29:13 +0000 Subject: [PATCH] update maintenance to delete only hourly metrics older than 3 months --- app/tasks/maintenance.php | 11 +++++------ app/workers/deletes.php | 10 ++-------- src/Appwrite/Event/Delete.php | 14 -------------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index e19870289..66b396f58 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -78,11 +78,10 @@ $cli ->trigger(); } - function notifyDeleteUsageStats(int $interval1h, int $interval1d) + function notifyDeleteUsageStats(int $interval1h) { (new Delete()) ->setType(DELETE_TYPE_USAGE) - ->setDateTime1d(DateTime::addSeconds(new \DateTime(), -1 * $interval1d)) ->setDateTime1h(DateTime::addSeconds(new \DateTime(), -1 * $interval1h)) ->trigger(); } @@ -144,11 +143,11 @@ $cli $executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600'); $auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', '1209600'); $abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', '86400'); - $usageStatsRetention1h = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_30M', '129600'); //36 hours - $usageStatsRetention1d = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1D', '8640000'); // 100 days + $usageStatsRetention1h = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1H', '8640000'); //100 days + $cacheRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_CACHE', '2592000'); // 30 days - Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention1h, $usageStatsRetention1d, $cacheRetention) { + Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention1h, $cacheRetention) { $database = getConsoleDB(); $time = DateTime::now(); @@ -157,7 +156,7 @@ $cli notifyDeleteExecutionLogs($executionLogsRetention); notifyDeleteAbuseLogs($abuseLogsRetention); notifyDeleteAuditLogs($auditLogRetention); - notifyDeleteUsageStats($usageStatsRetention1h, $usageStatsRetention1d); + notifyDeleteUsageStats($usageStatsRetention1h); notifyDeleteConnections(); notifyDeleteExpiredSessions(); renewCertificates($database); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index a5db6db5f..737dc96bb 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -217,16 +217,10 @@ class DeletesV1 extends Worker * @param string $datetime1d * @param string $datetime1h */ - protected function deleteUsageStats(string $datetime1d, string $datetime1h) + protected function deleteUsageStats(string $datetime1h) { - $this->deleteForProjectIds(function (string $projectId) use ($datetime1d, $datetime1h) { + $this->deleteForProjectIds(function (string $projectId) use ($datetime1h) { $dbForProject = $this->getProjectDB($projectId); - // Delete Usage stats - $this->deleteByGroup('stats', [ - Query::lessThan('time', $datetime1d), - Query::equal('period', ['1d']), - ], $dbForProject); - $this->deleteByGroup('stats', [ Query::lessThan('time', $datetime1h), Query::equal('period', ['1h']), diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index cd2461c6e..51d2bfa47 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -12,7 +12,6 @@ class Delete extends Event protected ?string $resource = null; protected ?string $datetime = null; protected ?string $dateTime1h = null; - protected ?string $dateTime1d = null; public function __construct() @@ -55,18 +54,6 @@ class Delete extends Event return $this; } - /** - * Set datetime for 1 day interval. - * - * @param string $datetime - * @return self - */ - public function setDateTime1d(string $datetime): self - { - $this->dateTime1d = $datetime; - return $this; - } - /** * Sets datetime for 1h interval. * @@ -140,7 +127,6 @@ class Delete extends Event 'document' => $this->document, 'resource' => $this->resource, 'datetime' => $this->datetime, - 'dateTime1d' => $this->dateTime1d, 'dateTime1h' => $this->dateTime1h, ]); }