diff --git a/.env b/.env index 0247356a25..3efd72e2a2 100644 --- a/.env +++ b/.env @@ -78,7 +78,7 @@ _APP_MAINTENANCE_RETENTION_CACHE=2592000 _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 _APP_MAINTENANCE_RETENTION_AUDIT=1209600 -_APP_USAGE_AGGREGATION_INTERVAL=60000 +_APP_USAGE_AGGREGATION_INTERVAL=60 _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 _APP_MAINTENANCE_RETENTION_SCHEDULES=86400 _APP_USAGE_STATS=enabled diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 7449ac27c0..5ce2263f47 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1189,16 +1189,15 @@ App::delete('/v1/users/:userId') // clone user object to send to workers $clone = clone $user; - $affected = $dbForProject->deleteDocument('users', $userId); - if (!empty($affected)) { - $queueForDeletes - ->setType(DELETE_TYPE_DOCUMENT) - ->setDocument($clone); + $dbForProject->deleteDocument('users', $userId); - $queueForEvents - ->setParam('userId', $user->getId()) - ->setPayload($response->output($clone, Response::MODEL_USER)); - } + $queueForDeletes + ->setType(DELETE_TYPE_DOCUMENT) + ->setDocument($clone); + + $queueForEvents + ->setParam('userId', $user->getId()) + ->setPayload($response->output($clone, Response::MODEL_USER)); $response->noContent(); }); diff --git a/docker-compose.yml b/docker-compose.yml index 2106ff8593..de71e3937a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -84,7 +84,6 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev - #- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database depends_on: - mariadb - redis diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 32f636a0f6..859fa6f97e 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Workers; use Exception; +use Utopia\App; use Utopia\CLI\Console; use Utopia\Database\Document; use Utopia\Platform\Action; @@ -15,9 +16,7 @@ class Usage extends Action private int $lastTriggeredTime = 0; private int $keys = 0; private const INFINITY_PERIOD = '_inf_'; - private const KEYS_THRESHOLD = 5; - private const KEYS_SENT_THRESHOLD = 60; - + private const KEYS_THRESHOLD = 10000; public static function getName(): string @@ -57,7 +56,9 @@ class Usage extends Action if (empty($payload)) { throw new Exception('Missing payload'); } + //Todo Figure out way to preserve keys when the container is being recreated @shimonewman + $aggregationInterval = (int) App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '60'); $project = new Document($payload['project'] ?? []); $projectId = $project->getInternalId(); foreach ($payload['reduce'] ?? [] as $document) { @@ -87,7 +88,7 @@ class Usage extends Action // if keys crossed threshold or X time passed since the last send and there are some keys in the array ($this->stats) if ( $this->keys >= self::KEYS_THRESHOLD || - (time() - $this->lastTriggeredTime > self::KEYS_SENT_THRESHOLD && $this->keys > 0) + (time() - $this->lastTriggeredTime > $aggregationInterval && $this->keys > 0) ) { $queueForUsageDump ->setStats($this->stats) diff --git a/src/Appwrite/Platform/Workers/UsageDump.php b/src/Appwrite/Platform/Workers/UsageDump.php index 24fe4ccccd..948b3fa681 100644 --- a/src/Appwrite/Platform/Workers/UsageDump.php +++ b/src/Appwrite/Platform/Workers/UsageDump.php @@ -55,6 +55,7 @@ class UsageDump extends Action throw new Exception('Missing payload'); } + //Todo rename both usage workers @shimonewman foreach ($payload['stats'] ?? [] as $stats) { $project = new Document($stats['project'] ?? []); $numberOfKeys = !empty($stats['keys']) ? count($stats['keys']) : 0;