diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 18a51a8634..c4c42483c6 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -174,8 +174,8 @@ App::error() ->inject('utopia') ->action(function (throwable $error, Request $request, Database $dbForProject, App $utopia) { try { - $route = $utopia->match($request); if ($error instanceof Timeout) { + $route = $utopia->match($request); $collectionId = $route->getParamValue('collectionId'); $databaseId = $route->getParamValue('databaseId'); $queries = $request->getParam('queries'); @@ -214,15 +214,13 @@ App::error() ]))); } else { $document['count']++; - $max = intval(App::getEnv('_APP_SLOW_QUERIES_MAX_HITS', 99999)); // todo: set default value - var_dump('_APP_SLOW_QUERIES_MAX_HITS'); - var_dump($max); - - if ($document['count'] > $max) { + $max = intval(App::getEnv('_APP_SLOW_QUERIES_MAX_HITS', 9999)); + if ($document['count'] >= $max) { $document['blocked'] = true; } $document = Authorization::skip(fn() => $dbForProject->updateDocument('slowQueries', $document->getId(), $document)); } + if ($document['blocked'] === true) { throw new Exception(Exception::TIMEOUT_BLOCKED); } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index b44d17b41d..4f00353877 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -997,8 +997,6 @@ trait DatabasesBase ]); $this->assertEquals(408, $documents['headers']['status-code']); - - exit(); } @@ -1013,7 +1011,6 @@ trait DatabasesBase ], $this->getHeaders()), [ 'queries' => ['sleep("$id", 1)'], ]); - $this->assertEquals(403, $documents['headers']['status-code']); }