diff --git a/src/Appwrite/Platform/Action.php b/src/Appwrite/Platform/Action.php index 72c41582ea..e5a7cf7984 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 @@ -87,4 +96,57 @@ class Action extends UtopiaAction $latestDocument = $results[array_key_last($results)]; } } + + public function disableSubqueries() + { + $filters = $this->filters; + + foreach ($filters as $filter) { + Database::addFilter( + $filter, + function (mixed $value) { + return; + }, + function (mixed $value, Document $document, Database $database) { + return []; + } + ); + } + } + + /** + * 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([]); + } + 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); + } + } } diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index bb7d3f8061..b64dd61f86 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -53,11 +53,14 @@ 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'); + Console::loop(function () use ($queue) { Authorization::disable(); Authorization::setDefaultStatus(false);