1
0
Fork 0
mirror of synced 2024-09-30 17:26:48 +13:00

Fix list complexity calculations

This commit is contained in:
Jake Barnby 2022-09-23 15:53:25 +12:00
parent 318bea760e
commit 63a4853563
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
3 changed files with 22 additions and 3 deletions

View file

@ -94,6 +94,7 @@ const APP_LIMIT_ARRAY_ELEMENT_SIZE = 4096; // Default maximum length of element
const APP_LIMIT_SUBQUERY = 1000;
const APP_LIMIT_WRITE_RATE_DEFAULT = 60; // Default maximum write rate per rate period
const APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT = 60; // Default maximum write rate period in seconds
const APP_LIMIT_LIST_DEFAULT = 25; // Default maximum number of items to return in list API calls
const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours
const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours
const APP_CACHE_BUSTER = 500;

View file

@ -127,8 +127,12 @@ class SchemaBuilder
$type = TypeRegistry::get($responseModel->getType());
$description = $route->getDesc();
$params = [];
$list = false;
foreach ($route->getParams() as $key => $value) {
if ($key === 'queries') {
$list = true;
}
$argType = TypeMapper::fromRouteParameter(
$utopia,
$value['validator'],
@ -149,6 +153,16 @@ class SchemaBuilder
'resolve' => Resolvers::resolveAPIRequest($utopia, $route)
];
if ($list) {
$field['complexity'] = function (int $complexity, array $args) {
$queries = Query::parseQueries($args['queries'] ?? []);
$query = Query::getByType($queries, Query::TYPE_LIMIT)[0] ?? null;
$limit = $query ? $query->getValue() : APP_LIMIT_LIST_DEFAULT;
return $complexity * $limit;
};
}
switch ($method) {
case 'GET':
$queryFields[$methodName] = $field;
@ -263,10 +277,14 @@ class SchemaBuilder
$collectionId
),
'complexity' => function (int $complexity, array $args) {
// FIXME: Update this for query limit
return $complexity; //* $args['limit'];
$queries = Query::parseQueries($args['queries'] ?? []);
$query = Query::getByType($queries, Query::TYPE_LIMIT)[0] ?? null;
$limit = $query ? $query->getValue() : APP_LIMIT_LIST_DEFAULT;
return $complexity * $limit;
},
];
$mutationFields[$collectionId . 'Create'] = [
'type' => $objectType,
'args' => $attributes,

View file

@ -372,7 +372,7 @@ class DatabaseServerTest extends Scope
public function testCreateIndex($data): array
{
// Wait for attributes to be available
sleep(2);
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_INDEX);