From 1ef5c9bfcd697035ca766cf051cd6ed39d335649 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 1 Feb 2024 10:32:40 +0200 Subject: [PATCH 1/4] removed var_dump leftovers --- src/Appwrite/Platform/Workers/Usage.php | 11 ------ src/Appwrite/Platform/Workers/UsageHook.php | 37 --------------------- 2 files changed, 48 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 5537fae504..1dffeb8bb6 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -70,16 +70,6 @@ class Usage extends Action getProjectDB: $getProjectDB ); } - if ($project->getInternalId() == self::DEBUG_PROJECT_ID) { - var_dump([ - 'type' => 'payload', - 'project' => $project->getInternalId(), - 'database' => $project['database'] ?? '', - $payload['metrics'] - ]); - - var_dump('=========================='); - } self::$stats[$projectId]['project'] = $project; foreach ($payload['metrics'] ?? [] as $metric) { @@ -91,7 +81,6 @@ class Usage extends Action } } - /** * On Documents that tied by relations like functions>deployments>build || documents>collection>database || buckets>files. * When we remove a parent document we need to deduct his children aggregation from the project scope. diff --git a/src/Appwrite/Platform/Workers/UsageHook.php b/src/Appwrite/Platform/Workers/UsageHook.php index 68e6a3fede..c897845516 100644 --- a/src/Appwrite/Platform/Workers/UsageHook.php +++ b/src/Appwrite/Platform/Workers/UsageHook.php @@ -47,8 +47,6 @@ class UsageHook extends Usage foreach ($projects as $data) { $numberOfKeys = !empty($data['keys']) ? count($data['keys']) : 0; $projectInternalId = $data['project']->getInternalId(); - $database = $data['project']['database'] ?? ''; - console::warning('Ticker started ' . DateTime::now()); if ($numberOfKeys === 0) { @@ -57,14 +55,6 @@ class UsageHook extends Usage try { $dbForProject = $getProjectDB($data['project']); - if ($projectInternalId == 85293) { - var_dump([ - 'project' => $projectInternalId, - 'database' => $database, - 'time' => DateTime::now(), - 'data' => $data['keys'] - ]); - } foreach ($data['keys'] ?? [] as $key => $value) { if ($value == 0) { continue; @@ -75,15 +65,6 @@ class UsageHook extends Usage $id = \md5("{$time}_{$period}_{$key}"); try { - if ($projectInternalId == self::DEBUG_PROJECT_ID) { - var_dump([ - 'type' => 'create', - 'period' => $period, - 'metric' => $key, - 'id' => $id, - 'value' => $value - ]); - } $dbForProject->createDocument('stats_v2', new Document([ '$id' => $id, 'period' => $period, @@ -94,15 +75,6 @@ class UsageHook extends Usage ])); } catch (Duplicate $th) { if ($value < 0) { - if ($projectInternalId == self::DEBUG_PROJECT_ID) { - var_dump([ - 'type' => 'decrease', - 'period' => $period, - 'metric' => $key, - 'id' => $id, - 'value' => $value - ]); - } $dbForProject->decreaseDocumentAttribute( 'stats_v2', $id, @@ -110,15 +82,6 @@ class UsageHook extends Usage abs($value) ); } else { - if ($projectInternalId == self::DEBUG_PROJECT_ID) { - var_dump([ - 'type' => 'increase', - 'period' => $period, - 'metric' => $key, - 'id' => $id, - 'value' => $value - ]); - } $dbForProject->increaseDocumentAttribute( 'stats_v2', $id, From 62bc540db02affd29083a3a9e38c66f51d466403 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 1 Feb 2024 10:35:38 +0200 Subject: [PATCH 2/4] removed var_dump leftovers --- src/Appwrite/Platform/Workers/UsageHook.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Appwrite/Platform/Workers/UsageHook.php b/src/Appwrite/Platform/Workers/UsageHook.php index c897845516..4781b1e892 100644 --- a/src/Appwrite/Platform/Workers/UsageHook.php +++ b/src/Appwrite/Platform/Workers/UsageHook.php @@ -47,6 +47,8 @@ class UsageHook extends Usage foreach ($projects as $data) { $numberOfKeys = !empty($data['keys']) ? count($data['keys']) : 0; $projectInternalId = $data['project']->getInternalId(); + $database = $data['project']['database'] ?? ''; + console::warning('Ticker started ' . DateTime::now()); if ($numberOfKeys === 0) { From ba4f708137694106a6490be929bbe7f9ed5fca67 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 8 Feb 2024 23:26:43 +0530 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Torsten Dittmann --- app/controllers/api/account.php | 4 ---- app/controllers/api/health.php | 4 ++-- app/controllers/api/teams.php | 5 +---- src/Appwrite/Platform/Tasks/QueueCount.php | 17 +++++------------ 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 1111293f3b..f1575a08d7 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1336,8 +1336,6 @@ App::post('/v1/account/sessions/phone') $message = $message->setParam('{{token}}', $secret); $message = $message->render(); - var_dump($request->getIP()); - var_dump($project->getId()); $queueForMessaging ->setRecipient($phone) ->setMessage($message) @@ -2939,8 +2937,6 @@ App::post('/v1/account/verification/phone') $message = $message->setParam('{{token}}', $secret); $message = $message->render(); - var_dump($request->getIP()); - var_dump($project->getId()); $queueForMessaging ->setRecipient($user->getAttribute('phone')) ->setMessage($message) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 1c5b68e9c3..a85f9da321 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -426,9 +426,9 @@ App::get('/v1/health/certificate') $sslExpiration = $certificatePayload['validTo_time_t']; - $status = ($sslExpiration < time()) ? 'fail' : 'pass'; + $status = $sslExpiration < time() ? 'fail' : 'pass'; - if ($status == 'fail') { + if ($status === 'fail') { throw new Exception(Exception::HEALTH_CERTIFICATE_EXPIRED); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 6baad094db..a374c57cf1 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -380,7 +380,6 @@ App::post('/v1/teams/:teamId/memberships') ->param('roles', [], new ArrayList(new Key(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 32 characters long.') ->param('url', '', fn($clients) => new Host($clients), 'URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true, ['clients']) // TODO add our own built-in confirm page ->param('name', '', new Text(128), 'Name of the new team member. Max length: 128 chars.', true) - ->inject('request') ->inject('response') ->inject('project') ->inject('user') @@ -389,7 +388,7 @@ App::post('/v1/teams/:teamId/memberships') ->inject('queueForMails') ->inject('queueForMessaging') ->inject('queueForEvents') - ->action(function (string $teamId, string $email, string $userId, string $phone, array $roles, string $url, string $name, Request $request, Response $response, Document $project, Document $user, Database $dbForProject, Locale $locale, Mail $queueForMails, EventPhone $queueForMessaging, Event $queueForEvents) { + ->action(function (string $teamId, string $email, string $userId, string $phone, array $roles, string $url, string $name, Response $response, Document $project, Document $user, Database $dbForProject, Locale $locale, Mail $queueForMails, EventPhone $queueForMessaging, Event $queueForEvents) { $isAPIKey = Auth::isAppUser(Authorization::getRoles()); $isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles()); @@ -639,8 +638,6 @@ App::post('/v1/teams/:teamId/memberships') $message = $message->setParam('{{token}}', $url); $message = $message->render(); - var_dump($request->getIP()); - var_dump($project->getId()); $queueForMessaging ->setRecipient($phone) ->setMessage($message) diff --git a/src/Appwrite/Platform/Tasks/QueueCount.php b/src/Appwrite/Platform/Tasks/QueueCount.php index 61d4750fac..4759a79d32 100644 --- a/src/Appwrite/Platform/Tasks/QueueCount.php +++ b/src/Appwrite/Platform/Tasks/QueueCount.php @@ -58,18 +58,11 @@ class QueueCount extends Action $queueClient = new Client($name, $queue); - $count = 0; - - switch ($type) { - case 'success': - $count = $queueClient->countSuccessfulJobs(); - break; - case 'failed': - $count = $queueClient->countFailedJobs(); - break; - case 'processing': - $count = $queueClient->countProcessingJobs(); - break; + $count = match($type) { + 'success' => $queueClient->countSuccessfulJobs(), + 'failed' => $queueClient->countFailedJobs(), + 'processing' => $queueClient->countProcessingJobs(), + default => 0 }; Console::log("Queue: '{$name}' has {$count} {$type} jobs."); From 5842f1950ab316590101b2d2da392846b60d957c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 8 Feb 2024 18:02:35 +0000 Subject: [PATCH 4/4] chore: linter --- composer.lock | 2 +- src/Appwrite/Platform/Tasks/QueueCount.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index e72cc04a15..ca39c7d084 100644 --- a/composer.lock +++ b/composer.lock @@ -5124,5 +5124,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Appwrite/Platform/Tasks/QueueCount.php b/src/Appwrite/Platform/Tasks/QueueCount.php index 4759a79d32..9b7bba82d1 100644 --- a/src/Appwrite/Platform/Tasks/QueueCount.php +++ b/src/Appwrite/Platform/Tasks/QueueCount.php @@ -58,7 +58,7 @@ class QueueCount extends Action $queueClient = new Client($name, $queue); - $count = match($type) { + $count = match ($type) { 'success' => $queueClient->countSuccessfulJobs(), 'failed' => $queueClient->countFailedJobs(), 'processing' => $queueClient->countProcessingJobs(),