From adbe11fd50974292653eec46e1019260912ba20e Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 12 Feb 2024 11:55:45 +0200 Subject: [PATCH 1/5] fix Indexes --- app/controllers/api/account.php | 4 +- app/controllers/api/databases.php | 37 +++++++++------ app/controllers/api/functions.php | 12 +++-- app/controllers/api/messaging.php | 40 ++++++++++++----- app/controllers/api/migrations.php | 4 +- app/controllers/api/projects.php | 4 +- app/controllers/api/proxy.php | 8 +++- app/controllers/api/storage.php | 8 +++- app/controllers/api/teams.php | 8 +++- app/controllers/api/users.php | 18 +++++--- app/controllers/api/vcs.php | 8 +++- composer.lock | 45 ++++++++----------- .../e2e/Services/Databases/DatabasesBase.php | 1 + 13 files changed, 127 insertions(+), 70 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 49eabcbf5c..595a4104c5 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -911,7 +911,9 @@ App::get('/v1/account/identities') $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c913fcca5d..0eacdab3b8 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -493,7 +493,9 @@ App::get('/v1/databases') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -815,7 +817,9 @@ App::get('/v1/databases/:databaseId/collections') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -1649,7 +1653,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') ->inject('response') ->inject('dbForProject') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject) { - + /** @var Document $database */ $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { @@ -1666,22 +1670,23 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') \array_push( $queries, - Query::equal('collectionId', [$collectionId]), - Query::equal('databaseId', [$databaseId]) + Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getInternalId()]) ); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); - $cursor = \reset($cursor); if ($cursor) { $attributeId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn() => $dbForProject->find('attributes', [ - Query::equal('collectionId', [$collectionId]), - Query::equal('databaseId', [$databaseId]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getInternalId()]), Query::equal('key', [$attributeId]), Query::limit(1), ])); @@ -2491,7 +2496,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') ->inject('response') ->inject('dbForProject') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject) { - + /** @var Document $database */ $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { @@ -2507,7 +2512,9 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') $queries = Query::parseQueries($queries); \array_push($queries, Query::equal('collectionId', [$collectionId]), Query::equal('databaseId', [$databaseId])); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -2516,8 +2523,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') if ($cursor) { $indexId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn() => $dbForProject->find('indexes', [ - Query::equal('collectionId', [$collectionId]), - Query::equal('databaseId', [$databaseId]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getInternalId()]), Query::equal('key', [$indexId]), Query::limit(1) ])); @@ -2914,7 +2921,9 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $queries = Query::parseQueries($queries); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 9c1f3cfa98..5b753fa86c 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -372,7 +372,9 @@ App::get('/v1/functions') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -1266,7 +1268,9 @@ App::get('/v1/functions/:functionId/deployments') $queries[] = Query::equal('resourceId', [$function->getId()]); $queries[] = Query::equal('resourceType', ['functions']); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -1803,7 +1807,9 @@ App::get('/v1/functions/:functionId/executions') // Set internal queries $queries[] = Query::equal('functionId', [$function->getId()]); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 25260e1071..d787dd5766 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -843,8 +843,12 @@ App::get('/v1/messaging/providers') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { @@ -1950,8 +1954,12 @@ App::get('/v1/messaging/topics') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { @@ -2272,8 +2280,12 @@ App::get('/v1/messaging/topics/:topicId/subscribers') \array_push($queries, Query::equal('topicInternalId', [$topic->getInternalId()])); - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { @@ -2851,8 +2863,12 @@ App::get('/v1/messaging/messages') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { @@ -2994,8 +3010,12 @@ App::get('/v1/messaging/messages/:messageId/targets') $queries[] = Query::equal('$id', $targetIDs); - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 87d3c12c99..eac9432d42 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -390,7 +390,9 @@ App::get('/v1/migrations') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 30f6b1f376..6b84c75d6b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -247,7 +247,9 @@ App::get('/v1/projects') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 3081b3def3..47e1fc0f2e 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -163,8 +163,12 @@ App::get('/v1/proxy/rules') $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index fc5d00dfd0..305888d4cf 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -167,7 +167,9 @@ App::get('/v1/storage/buckets') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -743,7 +745,9 @@ App::get('/v1/storage/buckets/:bucketId/files') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 685c230f4c..dc426abc6f 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -152,7 +152,9 @@ App::get('/v1/teams') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -708,7 +710,9 @@ App::get('/v1/teams/:teamId/memberships') // Set internal queries $queries[] = Query::equal('teamId', [$teamId]); - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 375efe77cb..b74fda251e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -542,7 +542,9 @@ App::get('/v1/users') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); @@ -838,9 +840,13 @@ App::get('/v1/users/:userId/targets') $queries[] = Query::equal('userId', [$userId]); - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); - $cursor = reset($cursor); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); + $cursor = reset($cursor); if ($cursor) { $targetId = $cursor->getValue(); @@ -882,7 +888,9 @@ App::get('/v1/users/identities') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); }); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index df18320cf2..096f57656d 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -977,8 +977,12 @@ App::get('/v1/vcs/installations') $queries[] = Query::search('search', $search); } - // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + /** + * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + */ + $cursor = \array_filter($queries, function ($query) { + return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); + }); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/composer.lock b/composer.lock index 226d55e38f..1429dfe408 100644 --- a/composer.lock +++ b/composer.lock @@ -1029,16 +1029,16 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", "shasum": "" }, "require": { @@ -1046,9 +1046,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1092,7 +1089,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" }, "funding": [ { @@ -1108,7 +1105,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "thecodingmachine/safe", @@ -5123,16 +5120,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -5146,9 +5143,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -5185,7 +5179,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -5201,20 +5195,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -5228,9 +5222,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -5268,7 +5259,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -5284,7 +5275,7 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "textalk/websocket", diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 7580d73711..90ea4d8fa7 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -492,6 +492,7 @@ trait DatabasesBase Query::cursorAfter(new Document(['$id' => 'title']))->toString() ], ]); + var_dump($response); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, \count($response['body']['attributes'])); $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes', array_merge([ From e5bada049379d58c850b95d2a260cb052776fdee Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 12 Feb 2024 12:03:31 +0200 Subject: [PATCH 2/5] typo --- app/controllers/api/account.php | 2 +- app/controllers/api/databases.php | 6 +++--- app/controllers/api/functions.php | 6 +++--- app/controllers/api/messaging.php | 10 +++++----- app/controllers/api/migrations.php | 2 +- app/controllers/api/projects.php | 2 +- app/controllers/api/proxy.php | 2 +- app/controllers/api/storage.php | 4 ++-- app/controllers/api/teams.php | 4 ++-- app/controllers/api/users.php | 6 +++--- app/controllers/api/vcs.php | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index d9d1f21098..306ceee51b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -912,7 +912,7 @@ App::get('/v1/account/identities') $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index f814768a54..bfefaf8e7f 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1675,7 +1675,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') ); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -2522,7 +2522,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') \array_push($queries, Query::equal('collectionId', [$collectionId]), Query::equal('databaseId', [$databaseId])); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -2931,7 +2931,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $queries = Query::parseQueries($queries); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5b753fa86c..8f57d6f3d9 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -373,7 +373,7 @@ App::get('/v1/functions') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -1269,7 +1269,7 @@ App::get('/v1/functions/:functionId/deployments') $queries[] = Query::equal('resourceType', ['functions']); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -1808,7 +1808,7 @@ App::get('/v1/functions/:functionId/executions') $queries[] = Query::equal('functionId', [$function->getId()]); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index d787dd5766..4b89befa27 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -844,7 +844,7 @@ App::get('/v1/messaging/providers') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -1955,7 +1955,7 @@ App::get('/v1/messaging/topics') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -2281,7 +2281,7 @@ App::get('/v1/messaging/topics/:topicId/subscribers') \array_push($queries, Query::equal('topicInternalId', [$topic->getInternalId()])); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -2864,7 +2864,7 @@ App::get('/v1/messaging/messages') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -3011,7 +3011,7 @@ App::get('/v1/messaging/messages/:messageId/targets') $queries[] = Query::equal('$id', $targetIDs); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index eac9432d42..442b06e448 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -391,7 +391,7 @@ App::get('/v1/migrations') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6b84c75d6b..e4d5226771 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -248,7 +248,7 @@ App::get('/v1/projects') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index c64033d274..96586797b2 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -165,7 +165,7 @@ App::get('/v1/proxy/rules') $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 305888d4cf..3e10d2a9fb 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -168,7 +168,7 @@ App::get('/v1/storage/buckets') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -746,7 +746,7 @@ App::get('/v1/storage/buckets/:bucketId/files') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 8986ce0c50..7d76843b37 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -153,7 +153,7 @@ App::get('/v1/teams') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -711,7 +711,7 @@ App::get('/v1/teams/:teamId/memberships') $queries[] = Query::equal('teamId', [$teamId]); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index b74fda251e..cdc622e89e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -543,7 +543,7 @@ App::get('/v1/users') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -841,7 +841,7 @@ App::get('/v1/users/:userId/targets') $queries[] = Query::equal('userId', [$userId]); /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); @@ -889,7 +889,7 @@ App::get('/v1/users/identities') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 096f57656d..80869950ee 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -978,7 +978,7 @@ App::get('/v1/vcs/installations') } /** - * Get cursor document if there was a cursor query, we user array_filter and reset for reference $cursor to $queries + * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries */ $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); From 74f7143a18a76ce4a47e18f78a6acc61e39d0839 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 12 Feb 2024 12:04:46 +0200 Subject: [PATCH 3/5] remove debug --- tests/e2e/Services/Databases/DatabasesBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index c3d6a005bc..ee8dde00db 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -492,7 +492,6 @@ trait DatabasesBase Query::cursorAfter(new Document(['$id' => 'title']))->toString() ], ]); - var_dump($response); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, \count($response['body']['attributes'])); $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes', array_merge([ From 6aae8cbf64cbc4a5292ab677a755cb18354e8ac6 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 12 Feb 2024 15:27:19 +0200 Subject: [PATCH 4/5] Add cursor test --- app/controllers/api/messaging.php | 6 +- .../e2e/Services/Messaging/MessagingBase.php | 55 +++++++++++++++---- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 4b89befa27..aa0f44ac68 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2987,9 +2987,7 @@ App::get('/v1/messaging/messages/:messageId/targets') ->param('queries', [], new Targets(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Targets::ALLOWED_ATTRIBUTES), true) ->inject('response') ->inject('dbForProject') - ->inject('locale') - ->inject('geodb') - ->action(function (string $messageId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $messageId, array $queries, Response $response, Database $dbForProject) { $message = $dbForProject->getDocument('messages', $messageId); if ($message->isEmpty()) { @@ -3028,7 +3026,7 @@ App::get('/v1/messaging/messages/:messageId/targets') $cursor->setValue($cursorDocument); } - +var_dump($queries); $response->dynamic(new Document([ 'targets' => $dbForProject->find('targets', $queries), 'total' => $dbForProject->count('targets', $queries, APP_LIMIT_COUNT), diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 59a5d5dec2..111f0294fc 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Messaging; use Appwrite\Messaging\Status as MessageStatus; use Tests\E2E\Client; use Utopia\App; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\DSN\DSN; @@ -682,12 +683,27 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ]); - $this->assertEquals(200, $response['headers']['status-code']); - $targetList = $response['body']; - $this->assertEquals(1, $targetList['total']); - $this->assertEquals(1, count($targetList['targets'])); + $this->assertEquals(2, $targetList['total']); + $this->assertEquals(2, count($targetList['targets'])); $this->assertEquals($message['targets'][0], $targetList['targets'][0]['$id']); + $this->assertEquals($message['targets'][1], $targetList['targets'][1]['$id']); + + /** + * Cursor Test + */ + $response = $this->client->call(Client::METHOD_GET, '/messaging/messages/' . $message['$id'] . '/targets', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'queries' => [ + Query::cursorAfter(new Document(['$id' => $targetList['targets'][0]['$id']]))->toString(), + ] + ]); + $this->assertEquals(2, $response['body']['total']); + $this->assertEquals(1, count($response['body']['targets'])); + $this->assertEquals($targetList['targets'][1]['$id'], $response['body']['targets'][0]['$id']); // Test for empty targets $response = $this->client->call(Client::METHOD_POST, '/messaging/messages/email', [ @@ -719,7 +735,7 @@ trait MessagingBase public function testCreateDraftEmail() { - // Create User + // Create User 1 $response = $this->client->call(Client::METHOD_POST, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -728,15 +744,33 @@ trait MessagingBase 'userId' => ID::unique(), 'email' => uniqid() . "@example.com", 'password' => 'password', - 'name' => 'Messaging User', + 'name' => 'Messaging User 1', ]); $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); - $user = $response['body']; + $user1 = $response['body']; - $this->assertEquals(1, \count($user['targets'])); - $targetId = $user['targets'][0]['$id']; + $this->assertEquals(1, \count($user1['targets'])); + $targetId1 = $user1['targets'][0]['$id']; + + // Create User 2 + $response = $this->client->call(Client::METHOD_POST, '/users', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'userId' => ID::unique(), + 'email' => uniqid() . "@example.com", + 'password' => 'password', + 'name' => 'Messaging User 2', + ]); + + $this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true)); + $user2 = $response['body']; + + $this->assertEquals(1, \count($user2['targets'])); + $targetId2 = $user2['targets'][0]['$id']; // Create Email $response = $this->client->call(Client::METHOD_POST, '/messaging/messages/email', [ @@ -745,13 +779,12 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'messageId' => ID::unique(), - 'targets' => [$targetId], + 'targets' => [$targetId1, $targetId2], 'subject' => 'New blog post', 'content' => 'Check out the new blog post at http://localhost', ]); $this->assertEquals(201, $response['headers']['status-code']); - $message = $response['body']; $this->assertEquals(MessageStatus::DRAFT, $message['status']); From 2f9cadf4c084d585351d444e07909567c543c954 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 12 Feb 2024 15:30:34 +0200 Subject: [PATCH 5/5] remove var_dump --- app/controllers/api/messaging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index aa0f44ac68..87dad03441 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -3026,7 +3026,7 @@ App::get('/v1/messaging/messages/:messageId/targets') $cursor->setValue($cursorDocument); } -var_dump($queries); + $response->dynamic(new Document([ 'targets' => $dbForProject->find('targets', $queries), 'total' => $dbForProject->count('targets', $queries, APP_LIMIT_COUNT),