diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index 42b5ed00dc..e198702894 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -78,12 +78,12 @@ $cli ->trigger(); } - function notifyDeleteUsageStats(int $interval30m, int $interval1d) + function notifyDeleteUsageStats(int $interval1h, int $interval1d) { (new Delete()) ->setType(DELETE_TYPE_USAGE) ->setDateTime1d(DateTime::addSeconds(new \DateTime(), -1 * $interval1d)) - ->setDateTime30m(DateTime::addSeconds(new \DateTime(), -1 * $interval30m)) + ->setDateTime1h(DateTime::addSeconds(new \DateTime(), -1 * $interval1h)) ->trigger(); } @@ -144,11 +144,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'); - $usageStatsRetention30m = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_30M', '129600'); //36 hours + $usageStatsRetention1h = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_30M', '129600'); //36 hours $usageStatsRetention1d = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1D', '8640000'); // 100 days $cacheRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_CACHE', '2592000'); // 30 days - Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention30m, $usageStatsRetention1d, $cacheRetention) { + Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention1h, $usageStatsRetention1d, $cacheRetention) { $database = getConsoleDB(); $time = DateTime::now(); @@ -157,7 +157,7 @@ $cli notifyDeleteExecutionLogs($executionLogsRetention); notifyDeleteAbuseLogs($abuseLogsRetention); notifyDeleteAuditLogs($auditLogRetention); - notifyDeleteUsageStats($usageStatsRetention30m, $usageStatsRetention1d); + notifyDeleteUsageStats($usageStatsRetention1h, $usageStatsRetention1d); notifyDeleteConnections(); notifyDeleteExpiredSessions(); renewCertificates($database); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index b015043b1d..a5db6db5f6 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -105,7 +105,7 @@ class DeletesV1 extends Worker break; case DELETE_TYPE_USAGE: - $this->deleteUsageStats($this->args['dateTime1d'], $this->args['dateTime30m']); + $this->deleteUsageStats($this->args['dateTime1d'], $this->args['dateTime1h']); break; case DELETE_TYPE_CACHE_BY_RESOURCE: @@ -215,11 +215,11 @@ class DeletesV1 extends Worker /** * @param string $datetime1d - * @param string $datetime30m + * @param string $datetime1h */ - protected function deleteUsageStats(string $datetime1d, string $datetime30m) + protected function deleteUsageStats(string $datetime1d, string $datetime1h) { - $this->deleteForProjectIds(function (string $projectId) use ($datetime1d, $datetime30m) { + $this->deleteForProjectIds(function (string $projectId) use ($datetime1d, $datetime1h) { $dbForProject = $this->getProjectDB($projectId); // Delete Usage stats $this->deleteByGroup('stats', [ @@ -228,8 +228,8 @@ class DeletesV1 extends Worker ], $dbForProject); $this->deleteByGroup('stats', [ - Query::lessThan('time', $datetime30m), - Query::equal('period', ['30m']), + Query::lessThan('time', $datetime1h), + Query::equal('period', ['1h']), ], $dbForProject); }); } diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index 72ace2a86d..cd2461c6e1 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -11,7 +11,7 @@ class Delete extends Event protected ?Document $document = null; protected ?string $resource = null; protected ?string $datetime = null; - protected ?string $dateTime30m = null; + protected ?string $dateTime1h = null; protected ?string $dateTime1d = null; @@ -68,14 +68,14 @@ class Delete extends Event } /** - * Sets datetime for 30m interval. + * Sets datetime for 1h interval. * * @param string $datetime * @return self */ - public function setDateTime30m(string $datetime): self + public function setDateTime1h(string $datetime): self { - $this->dateTime30m = $datetime; + $this->dateTime1h = $datetime; return $this; } @@ -141,7 +141,7 @@ class Delete extends Event 'resource' => $this->resource, 'datetime' => $this->datetime, 'dateTime1d' => $this->dateTime1d, - 'dateTime30m' => $this->dateTime30m, + 'dateTime1h' => $this->dateTime1h, ]); } } diff --git a/src/Appwrite/Usage/Calculators/Aggregator.php b/src/Appwrite/Usage/Calculators/Aggregator.php index 67cb18fe56..f28557a06b 100644 --- a/src/Appwrite/Usage/Calculators/Aggregator.php +++ b/src/Appwrite/Usage/Calculators/Aggregator.php @@ -187,7 +187,7 @@ class Aggregator extends Database $this->database->setNamespace('_' . $projectId); $value = (int) $this->database->sum('stats', 'value', [ Query::equal('metric', [$metric]), - Query::equal('period', ['30m']), + Query::equal('period', ['1h']), Query::greaterThanEqual('time', $beginOfDay), Query::lessThanEqual('time', $endOfDay), ]); diff --git a/src/Appwrite/Usage/Calculators/Database.php b/src/Appwrite/Usage/Calculators/Database.php index 74179fab0b..d760e6a0c0 100644 --- a/src/Appwrite/Usage/Calculators/Database.php +++ b/src/Appwrite/Usage/Calculators/Database.php @@ -15,8 +15,8 @@ class Database extends Calculator { protected array $periods = [ [ - 'key' => '30m', - 'multiplier' => 1800, + 'key' => '1h', + 'multiplier' => 3600, ], [ 'key' => '1d', @@ -48,7 +48,7 @@ class Database extends Calculator foreach ($this->periods as $options) { $period = $options['key']; $date = new \DateTime(); - if ($period === '30m') { + if ($period === '1h') { $minutes = $date->format('i') >= '30' ? "30" : "00"; $time = $date->format('Y-m-d H:' . $minutes . ':00'); } elseif ($period === '1d') {