Merge pull request #8802 from appwrite/fix-max-queries-size

Fix max queries values
This commit is contained in:
Jake Barnby 2024-10-16 22:37:17 +13:00 committed by GitHub
commit 8b6529934d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 12 deletions

View file

@ -130,6 +130,7 @@ const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange';
const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange';
const APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH = 1_073_741_824; // 2^32 bits / 4 bits per char
const APP_DATABASE_TIMEOUT_MILLISECONDS = 15_000;
const APP_DATABASE_QUERY_MAX_VALUES = 500;
const APP_STORAGE_UPLOADS = '/storage/uploads';
const APP_STORAGE_FUNCTIONS = '/storage/functions';
const APP_STORAGE_BUILDS = '/storage/builds';
@ -1398,7 +1399,8 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole,
$database
->setMetadata('host', \gethostname())
->setMetadata('project', $project->getId())
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS)
->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES);
try {
$dsn = new DSN($project->getAttribute('database'));
@ -1434,7 +1436,8 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) {
->setNamespace('_console')
->setMetadata('host', \gethostname())
->setMetadata('project', 'console')
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS)
->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES);
return $database;
}, ['pools', 'cache']);
@ -1458,7 +1461,8 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole,
$database
->setMetadata('host', \gethostname())
->setMetadata('project', $project->getId())
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS)
->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES);
if ($dsn->getHost() === System::getEnv('_APP_DATABASE_SHARED_TABLES', '')) {
$database

12
composer.lock generated
View file

@ -2175,16 +2175,16 @@
},
{
"name": "utopia-php/migration",
"version": "0.6.8",
"version": "0.6.9",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "c3740de52c1b616aa7f054d0fadb9207895b5279"
"reference": "ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/c3740de52c1b616aa7f054d0fadb9207895b5279",
"reference": "c3740de52c1b616aa7f054d0fadb9207895b5279",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b",
"reference": "ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b",
"shasum": ""
},
"require": {
@ -2225,9 +2225,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.6.8"
"source": "https://github.com/utopia-php/migration/tree/0.6.9"
},
"time": "2024-10-10T08:09:19+00:00"
"time": "2024-10-16T08:33:21+00:00"
},
{
"name": "utopia-php/mongo",

View file

@ -66,7 +66,7 @@ class Base extends Queries
new Limit(),
new Offset(),
new Cursor(),
new Filter($attributes),
new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES),
new Order($attributes),
];

View file

@ -2096,7 +2096,7 @@ trait DatabasesBase
*/
$conditions = [];
for ($i = 0; $i < 101; $i++) {
for ($i = 0; $i < APP_DATABASE_QUERY_MAX_VALUES + 1; $i++) {
$conditions[] = $i;
}
@ -2109,7 +2109,7 @@ trait DatabasesBase
],
]);
$this->assertEquals(400, $documents['headers']['status-code']);
$this->assertEquals('Invalid query: Query on attribute has greater than 100 values: releaseYear', $documents['body']['message']);
$this->assertEquals('Invalid query: Query on attribute has greater than '.APP_DATABASE_QUERY_MAX_VALUES.' values: releaseYear', $documents['body']['message']);
$value = '';