From b2f7ed48dd3e27a5770861d5f7118bd73f5e0981 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 17 Apr 2025 10:16:26 +0530 Subject: [PATCH] Simplify constructor usage by inlining message; limit try/catch to DB operations --- app/controllers/api/account.php | 3 +- app/controllers/api/databases.php | 49 +++++++++++++------------- app/controllers/api/functions.php | 23 ++++++------- app/controllers/api/messaging.php | 55 ++++++++++++++++-------------- app/controllers/api/migrations.php | 13 +++---- app/controllers/api/projects.php | 13 +++---- app/controllers/api/storage.php | 16 ++++----- app/controllers/api/teams.php | 18 +++++----- app/controllers/api/users.php | 39 +++++++++++---------- app/controllers/api/vcs.php | 5 ++- 10 files changed, 120 insertions(+), 114 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 85a7982f3c..55bfd69442 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -4849,8 +4849,7 @@ App::get('/v1/account/identities') try { $results = $dbForProject->find('identities', $queries); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } $total = $dbForProject->count('identities', $filterQueries, APP_LIMIT_COUNT); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index dfebfe2069..28ee3ebdf9 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -598,14 +598,15 @@ App::get('/v1/databases') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'databases' => $dbForProject->find('databases', $queries), - 'total' => $dbForProject->count('databases', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_DATABASE_LIST); + $databases = $dbForProject->find('databases', $queries); + $total = $dbForProject->count('databases', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'databases' => $databases, + 'total' => $total, + ]), Response::MODEL_DATABASE_LIST); }); App::get('/v1/databases/:databaseId') @@ -976,15 +977,17 @@ App::get('/v1/databases/:databaseId/collections') } $filterQueries = Query::groupByType($queries)['filters']; + try { - $response->dynamic(new Document([ - 'collections' => $dbForProject->find('database_' . $database->getInternalId(), $queries), - 'total' => $dbForProject->count('database_' . $database->getInternalId(), $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_COLLECTION_LIST); + $collections = $dbForProject->find('database_' . $database->getInternalId(), $queries); + $total = $dbForProject->count('database_' . $database->getInternalId(), $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'collections' => $collections, + 'total' => $total, + ]), Response::MODEL_COLLECTION_LIST); }); App::get('/v1/databases/:databaseId/collections/:collectionId') @@ -1994,11 +1997,10 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') $filters = Query::groupByType($queries)['filters']; try { $attributes = $dbForProject->find('attributes', $queries); + $total = $dbForProject->count('attributes', $filters, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForProject->count('attributes', $filters, APP_LIMIT_COUNT); $response->dynamic(new Document([ 'attributes' => $attributes, @@ -2995,14 +2997,16 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'total' => $dbForProject->count('indexes', $filterQueries, APP_LIMIT_COUNT), - 'indexes' => $dbForProject->find('indexes', $queries), - ]), Response::MODEL_INDEX_LIST); + $total = $dbForProject->count('indexes', $filterQueries, APP_LIMIT_COUNT); + $indexes = $dbForProject->find('indexes', $queries); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + + $response->dynamic(new Document([ + 'total' => $total, + 'indexes' => $indexes, + ]), Response::MODEL_INDEX_LIST); }); App::get('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') @@ -3468,8 +3472,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } $operations = 0; diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5ce8068c87..ceb167f705 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -485,14 +485,15 @@ App::get('/v1/functions') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'functions' => $dbForProject->find('functions', $queries), - 'total' => $dbForProject->count('functions', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_FUNCTION_LIST); + $functions = $dbForProject->find('functions', $queries); + $total = $dbForProject->count('functions', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'functions' => $functions, + 'total' => $total, + ]), Response::MODEL_FUNCTION_LIST); }); App::get('/v1/functions/runtimes') @@ -1544,11 +1545,10 @@ App::get('/v1/functions/:functionId/deployments') $filterQueries = Query::groupByType($queries)['filters']; try { $results = $dbForProject->find('deployments', $queries); + $total = $dbForProject->count('deployments', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForProject->count('deployments', $filterQueries, APP_LIMIT_COUNT); foreach ($results as $result) { $build = $dbForProject->getDocument('builds', $result->getAttribute('buildId', '')); @@ -2342,11 +2342,10 @@ App::get('/v1/functions/:functionId/executions') $filterQueries = Query::groupByType($queries)['filters']; try { $results = $dbForProject->find('executions', $queries); + $total = $dbForProject->count('executions', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForProject->count('executions', $filterQueries, APP_LIMIT_COUNT); $roles = Authorization::getRoles(); $isPrivilegedUser = Auth::isPrivilegedUser($roles); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 5683f05539..9dbd2f3403 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -953,14 +953,15 @@ App::get('/v1/messaging/providers') $cursor->setValue($cursorDocument); } try { - $response->dynamic(new Document([ - 'providers' => $dbForProject->find('providers', $queries), - 'total' => $dbForProject->count('providers', $queries, APP_LIMIT_COUNT), - ]), Response::MODEL_PROVIDER_LIST); + $providers = $dbForProject->find('providers', $queries); + $total = $dbForProject->count('providers', $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'providers' => $providers, + 'total' => $total, + ]), Response::MODEL_PROVIDER_LIST); }); App::get('/v1/messaging/providers/:providerId/logs') @@ -2187,14 +2188,15 @@ App::get('/v1/messaging/topics') $cursor->setValue($cursorDocument[0]); } try { - $response->dynamic(new Document([ - 'topics' => $dbForProject->find('topics', $queries), - 'total' => $dbForProject->count('topics', $queries, APP_LIMIT_COUNT), - ]), Response::MODEL_TOPIC_LIST); + $topics = $dbForProject->find('topics', $queries); + $total = $dbForProject->count('topics', $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'topics' => $topics, + 'total' => $total, + ]), Response::MODEL_TOPIC_LIST); }); App::get('/v1/messaging/topics/:topicId/logs') @@ -2591,8 +2593,7 @@ App::get('/v1/messaging/topics/:topicId/subscribers') try { $subscribers = $dbForProject->find('subscribers', $queries); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } $subscribers = batch(\array_map(function (Document $subscriber) use ($dbForProject) { @@ -3374,14 +3375,15 @@ App::get('/v1/messaging/messages') $cursor->setValue($cursorDocument); } try { - $response->dynamic(new Document([ - 'messages' => $dbForProject->find('messages', $queries), - 'total' => $dbForProject->count('messages', $queries, APP_LIMIT_COUNT), - ]), Response::MODEL_MESSAGE_LIST); + $messages = $dbForProject->find('messages', $queries); + $total = $dbForProject->count('messages', $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'messages' => $messages, + 'total' => $total, + ]), Response::MODEL_MESSAGE_LIST); }); App::get('/v1/messaging/messages/:messageId/logs') @@ -3551,14 +3553,15 @@ App::get('/v1/messaging/messages/:messageId/targets') $cursor->setValue($cursorDocument); } try { - $response->dynamic(new Document([ - 'targets' => $dbForProject->find('targets', $queries), - 'total' => $dbForProject->count('targets', $queries, APP_LIMIT_COUNT), - ]), Response::MODEL_TARGET_LIST); + $targets = $dbForProject->find('targets', $queries); + $total = $dbForProject->count('targets', $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'targets' => $targets, + 'total' => $total, + ]), Response::MODEL_TARGET_LIST); }); App::get('/v1/messaging/messages/:messageId') diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 17327ea764..9d8d69bc1b 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -349,14 +349,15 @@ App::get('/v1/migrations') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'migrations' => $dbForProject->find('migrations', $queries), - 'total' => $dbForProject->count('migrations', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_MIGRATION_LIST); + $migrations = $dbForProject->find('migrations', $queries); + $total = $dbForProject->count('migrations', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'migrations' => $migrations, + 'total' => $total, + ]), Response::MODEL_MIGRATION_LIST); }); App::get('/v1/migrations/:migrationId') diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 1762c565c7..22facc0b23 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -359,14 +359,15 @@ App::get('/v1/projects') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'projects' => $dbForPlatform->find('projects', $queries), - 'total' => $dbForPlatform->count('projects', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_PROJECT_LIST); + $projects = $dbForPlatform->find('projects', $queries); + $total = $dbForPlatform->count('projects', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'projects' => $projects, + 'total' => $total, + ]), Response::MODEL_PROJECT_LIST); }); App::get('/v1/projects/:projectId') diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 388a015cb5..398369317f 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -218,14 +218,15 @@ App::get('/v1/storage/buckets') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'buckets' => $dbForProject->find('buckets', $queries), - 'total' => $dbForProject->count('buckets', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_BUCKET_LIST); + $buckets = $dbForProject->find('buckets', $queries); + $total = $dbForProject->count('buckets', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'buckets' => $buckets, + 'total' => $total, + ]), Response::MODEL_BUCKET_LIST); }); App::get('/v1/storage/buckets/:bucketId') @@ -843,8 +844,7 @@ App::get('/v1/storage/buckets/:bucketId/files') } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } $response->dynamic(new Document([ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index f9f663acb1..e5d3bb8bd0 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -207,11 +207,10 @@ App::get('/v1/teams') $filterQueries = Query::groupByType($queries)['filters']; try { $results = $dbForProject->find('teams', $queries); + $total = $dbForProject->count('teams', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForProject->count('teams', $filterQueries, APP_LIMIT_COUNT); $response->dynamic(new Document([ 'teams' => $results, @@ -869,16 +868,15 @@ App::get('/v1/teams/:teamId/memberships') collection: 'memberships', queries: $queries, ); + $total = $dbForProject->count( + collection: 'memberships', + queries: $filterQueries, + max: APP_LIMIT_COUNT + ); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForProject->count( - collection: 'memberships', - queries: $filterQueries, - max: APP_LIMIT_COUNT - ); $memberships = array_filter($memberships, fn (Document $membership) => !empty($membership->getAttribute('userId'))); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 0b1b90f800..4a02b94bdd 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -632,14 +632,15 @@ App::get('/v1/users') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'users' => $dbForProject->find('users', $queries), - 'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_USER_LIST); + $users = $dbForProject->find('users', $queries); + $total = $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'users' => $users, + 'total' => $total, + ]), Response::MODEL_USER_LIST); }); App::get('/v1/users/:userId') @@ -986,14 +987,15 @@ App::get('/v1/users/:userId/targets') $cursor->setValue($cursorDocument); } try { - $response->dynamic(new Document([ - 'targets' => $dbForProject->find('targets', $queries), - 'total' => $dbForProject->count('targets', $queries, APP_LIMIT_COUNT), - ]), Response::MODEL_TARGET_LIST); + $targets = $dbForProject->find('targets', $queries); + $total = $dbForProject->count('targets', $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'targets' => $targets, + 'total' => $total, + ]), Response::MODEL_TARGET_LIST); }); App::get('/v1/users/identities') @@ -1055,14 +1057,15 @@ App::get('/v1/users/identities') $filterQueries = Query::groupByType($queries)['filters']; try { - $response->dynamic(new Document([ - 'identities' => $dbForProject->find('identities', $queries), - 'total' => $dbForProject->count('identities', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_IDENTITY_LIST); + $identities = $dbForProject->find('identities', $queries); + $total = $dbForProject->count('identities', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } + $response->dynamic(new Document([ + 'identities' => $identities, + 'total' => $total, + ]), Response::MODEL_IDENTITY_LIST); }); App::patch('/v1/users/:userId/status') diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index a230ae5d0c..e09367f790 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -1116,11 +1116,10 @@ App::get('/v1/vcs/installations') $filterQueries = Query::groupByType($queries)['filters']; try { $results = $dbForPlatform->find('installations', $queries); + $total = $dbForPlatform->count('installations', $filterQueries, APP_LIMIT_COUNT); } catch (OrderException $e) { - $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; - throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - $total = $dbForPlatform->count('installations', $filterQueries, APP_LIMIT_COUNT); $response->dynamic(new Document([ 'installations' => $results,