From 17428ef433dc3c8453bc392e53a759644bc917d9 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 25 Jun 2025 14:18:22 +0400 Subject: [PATCH 1/7] refactor: replace Console loop with Swoole Timer for stats resource management --- src/Appwrite/Platform/Tasks/StatsResources.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index a0b5056b0f..eb707835e5 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Tasks; use Appwrite\Event\StatsResources as EventStatsResources; use Appwrite\Platform\Action; +use Swoole\Timer; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -58,7 +59,7 @@ class StatsResources extends Action Console::success('Stats resources: started'); $interval = (int) System::getEnv('_APP_STATS_RESOURCES_INTERVAL', '3600'); - Console::loop(function () use ($queue) { + Timer::tick($interval, function () use ($queue) { Authorization::disable(); Authorization::setDefaultStatus(false); @@ -75,7 +76,7 @@ class StatsResources extends Action ->trigger(); Console::success('project: ' . $project->getId() . '(' . $project->getSequence() . ')' . ' queued'); }); - }, $interval); + }); Console::log("Stats resources: exited"); } From c268b632fb4686781a79b61e086fb2ef1679ff22 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 25 Jun 2025 14:52:13 +0400 Subject: [PATCH 2/7] chore: update benchmark command to use JSON output format and adjust timer interval in StatsResources --- .github/workflows/benchmark.yml | 2 +- src/Appwrite/Platform/Tasks/StatsResources.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 6d73787d00..62256a41c6 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -65,7 +65,7 @@ jobs: sudo apt update sudo apt install oha - name: Benchmark PR - run: 'oha -z 180s http://localhost/v1/health/version -j > benchmark.json' + run: 'oha -z 180s http://localhost/v1/health/version --output-format json > benchmark.json' - name: Cleaning run: docker compose down -v - name: Installing latest version diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index eb707835e5..30ed3033b6 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -59,7 +59,7 @@ class StatsResources extends Action Console::success('Stats resources: started'); $interval = (int) System::getEnv('_APP_STATS_RESOURCES_INTERVAL', '3600'); - Timer::tick($interval, function () use ($queue) { + Timer::tick($interval * 1000, function () use ($queue) { Authorization::disable(); Authorization::setDefaultStatus(false); From 3cd31e2c069a52a9a3f64021efdb209c85f03b6a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 25 Jun 2025 21:46:15 +0400 Subject: [PATCH 3/7] Add disableSubqueries method to Action class and integrate it into StatsResources initialization --- src/Appwrite/Platform/Action.php | 21 +++++++++++++++++++ .../Platform/Tasks/StatsResources.php | 8 ++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Action.php b/src/Appwrite/Platform/Action.php index 72c41582ea..cd06df74fe 100644 --- a/src/Appwrite/Platform/Action.php +++ b/src/Appwrite/Platform/Action.php @@ -87,4 +87,25 @@ class Action extends UtopiaAction $latestDocument = $results[array_key_last($results)]; } } + + public function disableSubqueries() + { + $filters = [ + 'subQueryKeys', 'subQueryWebhooks', 'subQueryPlatforms', 'subQueryProjectVariables', 'subQueryBlocks', 'subQueryDevKeys', // Project + 'subQueryAuthenticators', 'subQuerySessions', 'subQueryTokens', 'subQueryChallenges', 'subQueryMemberships', 'subQueryTargets', 'subQueryTopicTargets',// Users + 'subQueryVariables', // Sites + ]; + + foreach ($filters as $filter) { + Database::addFilter( + $filter, + function (mixed $value) { + return; + }, + function (mixed $value, Document $document, Database $database) { + return []; + } + ); + } + } } diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index 0610dd0df6..b64dd61f86 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -4,7 +4,6 @@ namespace Appwrite\Platform\Tasks; use Appwrite\Event\StatsResources as EventStatsResources; use Appwrite\Platform\Action; -use Swoole\Timer; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -54,12 +53,15 @@ class StatsResources extends Action $this->logError = $logError; $this->dbForPlatform = $dbForPlatform; + $this->disableSubqueries(); + Console::title("Stats resources V1"); Console::success('Stats resources: started'); $interval = (int) System::getEnv('_APP_STATS_RESOURCES_INTERVAL', '3600'); - Timer::tick($interval * 1000, function () use ($queue) { + + Console::loop(function () use ($queue) { Authorization::disable(); Authorization::setDefaultStatus(false); @@ -76,7 +78,7 @@ class StatsResources extends Action ->trigger(); Console::success('project: ' . $project->getId() . '(' . $project->getSequence() . ')' . ' queued'); }); - }); + }, $interval); Console::log("Stats resources: exited"); } From c479a11850934a4c8d01875cd0f8e79e2822afe7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 25 Jun 2025 21:56:30 +0400 Subject: [PATCH 4/7] Add logging functionality to Action class with dump method and refactor disableSubqueries to use class filters --- src/Appwrite/Platform/Action.php | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Action.php b/src/Appwrite/Platform/Action.php index cd06df74fe..96444f9144 100644 --- a/src/Appwrite/Platform/Action.php +++ b/src/Appwrite/Platform/Action.php @@ -3,7 +3,10 @@ namespace Appwrite\Platform; use Swoole\Coroutine as Co; +use Utopia\CLI\Console; use Utopia\Database\Database; +use Utopia\Database\DateTime; +use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Platform\Action as UtopiaAction; @@ -16,6 +19,12 @@ class Action extends UtopiaAction */ protected mixed $logError; + protected array $filters = [ + 'subQueryKeys', 'subQueryWebhooks', 'subQueryPlatforms', 'subQueryProjectVariables', 'subQueryBlocks', 'subQueryDevKeys', // Project + 'subQueryAuthenticators', 'subQuerySessions', 'subQueryTokens', 'subQueryChallenges', 'subQueryMemberships', 'subQueryTargets', 'subQueryTopicTargets',// Users + 'subQueryVariables', // Sites + ]; + /** * Foreach Document * Call provided callback for each document in the collection @@ -90,11 +99,7 @@ class Action extends UtopiaAction public function disableSubqueries() { - $filters = [ - 'subQueryKeys', 'subQueryWebhooks', 'subQueryPlatforms', 'subQueryProjectVariables', 'subQueryBlocks', 'subQueryDevKeys', // Project - 'subQueryAuthenticators', 'subQuerySessions', 'subQueryTokens', 'subQueryChallenges', 'subQueryMemberships', 'subQueryTargets', 'subQueryTopicTargets',// Users - 'subQueryVariables', // Sites - ]; + $filters = $this->filters; foreach ($filters as $filter) { Database::addFilter( @@ -108,4 +113,27 @@ class Action extends UtopiaAction ); } } + + public function dump(string $method, string $log, string $type = 'info', ?Document $project = null, string $collectionId = '') + { + if (empty($project)) { + $project = new Document([]); + } + switch ($type) { + case 'success': + Console::success("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log); + break; + case 'error': + Console::error("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log); + break; + case 'log': + Console::log("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log); + break; + case 'warning': + Console::warning("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log); + break; + default: + Console::info("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log); + } + } } From dbc7e5b42d0a9b789446cc8b9079d5e708907613 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 26 Jun 2025 15:05:10 +0400 Subject: [PATCH 5/7] Fix output format flag in benchmark workflow for consistency --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 562f2223f3..f1051497a8 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -65,7 +65,7 @@ jobs: sudo apt update sudo apt install oha - name: Benchmark PR - run: 'oha -z 180s http://localhost/v1/health/version --output_format json > benchmark.json' + run: 'oha -z 180s http://localhost/v1/health/version --output-format json > benchmark.json' - name: Cleaning run: docker compose down -v - name: Installing latest version @@ -78,7 +78,7 @@ jobs: docker compose up -d sleep 10 - name: Benchmark Latest - run: oha -z 180s http://localhost/v1/health/version --output_format json > benchmark-latest.json + run: oha -z 180s http://localhost/v1/health/version --output-format json > benchmark-latest.json - name: Prepare comment run: | echo '## :sparkles: Benchmark results' > benchmark.txt From 5761320bfb953d92cd2601a0fc553dfd9650f07e Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 26 Jun 2025 15:05:55 +0400 Subject: [PATCH 6/7] Update src/Appwrite/Platform/Action.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/Appwrite/Platform/Action.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Action.php b/src/Appwrite/Platform/Action.php index 96444f9144..fda6209d5f 100644 --- a/src/Appwrite/Platform/Action.php +++ b/src/Appwrite/Platform/Action.php @@ -114,7 +114,20 @@ class Action extends UtopiaAction } } - public function dump(string $method, string $log, string $type = 'info', ?Document $project = null, string $collectionId = '') + /** + * Dump Log Message + * + * Logs messages to console with timestamp, method context, and project details. + * Supports multiple log types: success, error, log, warning, and info (default). + * + * @param string $method The calling method name + * @param string $log The log message + * @param string $type The log type (success, error, log, warning, info) + * @param Document|null $project The project document for context + * @param string $collectionId The collection identifier + * @return void + */ + public function dump(string $method, string $log, string $type = 'info', ?Document $project = null, string $collectionId = ''): void { if (empty($project)) { $project = new Document([]); From 204b00850d6e6311221adbbd7a5b84cded2ce289 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 26 Jun 2025 15:09:57 +0400 Subject: [PATCH 7/7] Refactor log message documentation in Action class to improve clarity and formatting --- src/Appwrite/Platform/Action.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Action.php b/src/Appwrite/Platform/Action.php index fda6209d5f..e5a7cf7984 100644 --- a/src/Appwrite/Platform/Action.php +++ b/src/Appwrite/Platform/Action.php @@ -116,10 +116,10 @@ class Action extends UtopiaAction /** * Dump Log Message - * + * * Logs messages to console with timestamp, method context, and project details. * Supports multiple log types: success, error, log, warning, and info (default). - * + * * @param string $method The calling method name * @param string $log The log message * @param string $type The log type (success, error, log, warning, info)