From ae3535de0dc27774672645ed903b8b4aef78bdf3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Feb 2023 19:03:15 +1300 Subject: [PATCH] Remove count, limit and offset limitations --- app/controllers/api/account.php | 6 +-- app/controllers/api/databases.php | 26 +++++------ app/controllers/api/functions.php | 6 +-- app/controllers/api/projects.php | 6 +-- app/controllers/api/storage.php | 6 +-- app/controllers/api/teams.php | 11 ++--- app/controllers/api/users.php | 8 ++-- app/init.php | 1 - composer.json | 6 +-- composer.lock | 78 +++++++++++++++++++------------ 10 files changed, 84 insertions(+), 70 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 1a5d6f7b00..1174469313 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1397,7 +1397,7 @@ App::get('/v1/account/logs') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('user') ->inject('locale') @@ -1407,8 +1407,8 @@ App::get('/v1/account/logs') $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new EventAudit($dbForProject); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 88242482a1..11de905af6 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -265,7 +265,7 @@ App::get('/v1/databases') $response->dynamic(new Document([ 'databases' => $dbForProject->find('databases', $queries), - 'total' => $dbForProject->count('databases', $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForProject->count('databases', $filterQueries), ]), Response::MODEL_DATABASE_LIST); }); @@ -307,7 +307,7 @@ App::get('/v1/databases/:databaseId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -322,8 +322,8 @@ App::get('/v1/databases/:databaseId/logs') $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new Audit($dbForProject); $resource = 'database/' . $databaseId; @@ -590,7 +590,7 @@ App::get('/v1/databases/:databaseId/collections') $response->dynamic(new Document([ 'collections' => $dbForProject->find('database_' . $database->getInternalId(), $queries), - 'total' => $dbForProject->count('database_' . $database->getInternalId(), $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForProject->count('database_' . $database->getInternalId(), $filterQueries), ]), Response::MODEL_COLLECTION_LIST); }); @@ -645,7 +645,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID.') - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -666,8 +666,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new Audit($dbForProject); $resource = 'database/' . $databaseId . '/collection/' . $collectionId; @@ -2036,10 +2036,10 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') if ($documentSecurity && !$valid) { $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); - $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries, APP_LIMIT_COUNT); + $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries); } else { $documents = Authorization::skip(fn () => $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries)); - $total = Authorization::skip(fn () => $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries, APP_LIMIT_COUNT)); + $total = Authorization::skip(fn () => $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries)); } /** @@ -2136,7 +2136,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID.') ->param('documentId', '', new UID(), 'Document ID.') - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -2163,8 +2163,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new Audit($dbForProject); $resource = 'database/' . $databaseId . '/collection/' . $collectionId . '/document/' . $document->getId(); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 049d2cb850..e0cf4d3c8d 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -156,7 +156,7 @@ App::get('/v1/functions') $response->dynamic(new Document([ 'functions' => $dbForProject->find('functions', $queries), - 'total' => $dbForProject->count('functions', $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForProject->count('functions', $filterQueries), ]), Response::MODEL_FUNCTION_LIST); }); @@ -831,7 +831,7 @@ App::get('/v1/functions/:functionId/deployments') $filterQueries = Query::groupByType($queries)['filters']; $results = $dbForProject->find('deployments', $queries); - $total = $dbForProject->count('deployments', $filterQueries, APP_LIMIT_COUNT); + $total = $dbForProject->count('deployments', $filterQueries); foreach ($results as $result) { $build = $dbForProject->getDocument('builds', $result->getAttribute('buildId', '')); @@ -1265,7 +1265,7 @@ App::get('/v1/functions/:functionId/executions') $filterQueries = Query::groupByType($queries)['filters']; $results = $dbForProject->find('executions', $queries); - $total = $dbForProject->count('executions', $filterQueries, APP_LIMIT_COUNT); + $total = $dbForProject->count('executions', $filterQueries); $roles = Authorization::getRoles(); $isPrivilegedUser = Auth::isPrivilegedUser($roles); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 29a193748d..d33283f41e 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -215,7 +215,7 @@ App::get('/v1/projects') $response->dynamic(new Document([ 'projects' => $dbForConsole->find('projects', $queries), - 'total' => $dbForConsole->count('projects', $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForConsole->count('projects', $filterQueries), ]), Response::MODEL_PROJECT_LIST); }); @@ -726,7 +726,6 @@ App::get('/v1/projects/:projectId/webhooks') $webhooks = $dbForConsole->find('webhooks', [ Query::equal('projectInternalId', [$project->getInternalId()]), - Query::limit(5000), ]); $response->dynamic(new Document([ @@ -974,7 +973,6 @@ App::get('/v1/projects/:projectId/keys') $keys = $dbForConsole->find('keys', [ Query::equal('projectInternalId', [$project->getInternalId()]), - Query::limit(5000), ]); $response->dynamic(new Document([ @@ -1176,7 +1174,6 @@ App::get('/v1/projects/:projectId/platforms') $platforms = $dbForConsole->find('platforms', [ Query::equal('projectId', [$project->getId()]), - Query::limit(5000), ]); $response->dynamic(new Document([ @@ -1394,7 +1391,6 @@ App::get('/v1/projects/:projectId/domains') $domains = $dbForConsole->find('domains', [ Query::equal('projectInternalId', [$project->getInternalId()]), - Query::limit(5000), ]); $response->dynamic(new Document([ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 271f2af6b3..c42919282c 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -185,7 +185,7 @@ App::get('/v1/storage/buckets') $response->dynamic(new Document([ 'buckets' => $dbForProject->find('buckets', $queries), - 'total' => $dbForProject->count('buckets', $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForProject->count('buckets', $filterQueries), ]), Response::MODEL_BUCKET_LIST); }); @@ -730,10 +730,10 @@ App::get('/v1/storage/buckets/:bucketId/files') if ($fileSecurity && !$valid) { $files = $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries); - $total = $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT); + $total = $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries); } else { $files = Authorization::skip(fn () => $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries)); - $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT)); + $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries)); } $response->dynamic(new Document([ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index f7ebae6381..0e33fd6049 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -163,7 +163,7 @@ App::get('/v1/teams') $filterQueries = Query::groupByType($queries)['filters']; $results = $dbForProject->find('teams', $queries); - $total = $dbForProject->count('teams', $filterQueries, APP_LIMIT_COUNT); + $total = $dbForProject->count('teams', $filterQueries); $response->dynamic(new Document([ 'teams' => $results, @@ -542,8 +542,7 @@ App::get('/v1/teams/:teamId/memberships') $total = $dbForProject->count( collection: 'memberships', - queries: $filterQueries, - max: APP_LIMIT_COUNT + queries: $filterQueries ); $memberships = array_filter($memberships, fn(Document $membership) => !empty($membership->getAttribute('userId'))); @@ -890,7 +889,7 @@ App::get('/v1/teams/:teamId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->param('teamId', '', new UID(), 'Team ID.') - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -905,8 +904,8 @@ App::get('/v1/teams/:teamId/logs') $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new Audit($dbForProject); $resource = 'team/' . $team->getId(); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 2a84c06675..4cc832975f 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -390,7 +390,7 @@ App::get('/v1/users') $response->dynamic(new Document([ 'users' => $dbForProject->find('users', $queries), - 'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT), + 'total' => $dbForProject->count('users', $filterQueries), ]), Response::MODEL_USER_LIST); }); @@ -543,7 +543,7 @@ App::get('/v1/users/:userId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->param('userId', '', new UID(), 'User ID.') - ->param('queries', [], new Queries(new Limit(), new Offset()), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) + ->param('queries', [], new Queries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -558,8 +558,8 @@ App::get('/v1/users/:userId/logs') $queries = Query::parseQueries($queries); $grouped = Query::groupByType($queries); - $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; - $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + $offset = $grouped['offset'] ?? null; $audit = new Audit($dbForProject); diff --git a/app/init.php b/app/init.php index 44cda7a688..a37542c613 100644 --- a/app/init.php +++ b/app/init.php @@ -84,7 +84,6 @@ const APP_USERAGENT = APP_NAME . '-Server v%s. Please report abuse at %s'; const APP_MODE_DEFAULT = 'default'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 12; -const APP_LIMIT_COUNT = 5000; const APP_LIMIT_USERS = 10000; const APP_LIMIT_USER_SESSIONS_MAX = 100; const APP_LIMIT_USER_SESSIONS_DEFAULT = 10; diff --git a/composer.json b/composer.json index 1711407ece..d5658104f3 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "0.18.*", + "utopia-php/abuse": "dev-feat-remove-limits as 0.18.0", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.20.*", + "utopia-php/audit": "dev-feat-remove-limits as 0.20.0", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.30.*", + "utopia-php/database": "dev-refactor-limits as 0.30.1", "utopia-php/preloader": "0.2.*", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.26.*", diff --git a/composer.lock b/composer.lock index 82a9de301f..f82c13c063 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac80cafdd8c2c6deaec3dfe628084655", + "content-hash": "3143c47027eeb7f880d909543cc66a48", "packages": [ { "name": "adhocore/jwt", @@ -1808,29 +1808,28 @@ }, { "name": "utopia-php/abuse", - "version": "0.18.0", + "version": "dev-feat-remove-limits", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "8496401234f73a49f8c4259d3e89ab4a7c1f9ecf" + "reference": "51dfdc53125eba3c377322976104a5eca45651b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8496401234f73a49f8c4259d3e89ab4a7c1f9ecf", - "reference": "8496401234f73a49f8c4259d3e89ab4a7c1f9ecf", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/51dfdc53125eba3c377322976104a5eca45651b9", + "reference": "51dfdc53125eba3c377322976104a5eca45651b9", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.30.*" + "utopia-php/database": "dev-refactor-limits as 0.30.1" }, "require-dev": { "laravel/pint": "1.2.*", - "phpstan/phpstan": "1.9.x-dev", - "phpunit/phpunit": "^9.4", - "vimeo/psalm": "4.0.1" + "phpstan/phpstan": "^1.9", + "phpunit/phpunit": "^9.4" }, "type": "library", "autoload": { @@ -1852,9 +1851,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.18.0" + "source": "https://github.com/utopia-php/abuse/tree/feat-remove-limits" }, - "time": "2023-02-14T09:56:04+00:00" + "time": "2023-02-20T04:11:09+00:00" }, { "name": "utopia-php/analytics", @@ -1913,28 +1912,26 @@ }, { "name": "utopia-php/audit", - "version": "0.20.0", + "version": "dev-feat-remove-limits", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "3fce3f4ad3ea9dfcb39b79668abd76331412a5ed" + "reference": "c3fe31ead91bdb7cd41e61df4dde76ef4a58661e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/3fce3f4ad3ea9dfcb39b79668abd76331412a5ed", - "reference": "3fce3f4ad3ea9dfcb39b79668abd76331412a5ed", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/c3fe31ead91bdb7cd41e61df4dde76ef4a58661e", + "reference": "c3fe31ead91bdb7cd41e61df4dde76ef4a58661e", "shasum": "" }, "require": { - "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.30.*" + "utopia-php/database": "dev-refactor-limits as 0.30.1" }, "require-dev": { "laravel/pint": "1.2.*", "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" + "phpunit/phpunit": "^9.3" }, "type": "library", "autoload": { @@ -1956,9 +1953,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.20.0" + "source": "https://github.com/utopia-php/audit/tree/feat-remove-limits" }, - "time": "2023-02-14T09:46:54+00:00" + "time": "2023-02-20T03:50:56+00:00" }, { "name": "utopia-php/cache", @@ -2115,16 +2112,16 @@ }, { "name": "utopia-php/database", - "version": "0.30.1", + "version": "dev-refactor-limits", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "1cea72c1217357bf0747ae4f28ebef57e9dc0e65" + "reference": "d83a3e820c641ba0132c076172be9397df943a89" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/1cea72c1217357bf0747ae4f28ebef57e9dc0e65", - "reference": "1cea72c1217357bf0747ae4f28ebef57e9dc0e65", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d83a3e820c641ba0132c076172be9397df943a89", + "reference": "d83a3e820c641ba0132c076172be9397df943a89", "shasum": "" }, "require": { @@ -2163,9 +2160,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.30.1" + "source": "https://github.com/utopia-php/database/tree/refactor-limits" }, - "time": "2023-02-14T06:25:03+00:00" + "time": "2023-02-15T07:32:21+00:00" }, { "name": "utopia-php/domains", @@ -5564,9 +5561,32 @@ "time": "2023-02-08T07:49:20+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/abuse", + "version": "dev-feat-remove-limits", + "alias": "0.18.0", + "alias_normalized": "0.18.0.0" + }, + { + "package": "utopia-php/audit", + "version": "dev-feat-remove-limits", + "alias": "0.20.0", + "alias_normalized": "0.20.0.0" + }, + { + "package": "utopia-php/database", + "version": "dev-refactor-limits", + "alias": "0.30.1", + "alias_normalized": "0.30.1.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/abuse": 20, + "utopia-php/audit": 20, + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": {