mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'feat-database-indexing' of github.com:appwrite/appwrite into feat-new-usage-endpoints
This commit is contained in:
@@ -15,6 +15,7 @@ use Utopia\Validator\JSON;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
use Utopia\Database\Validator\Key;
|
||||
use Utopia\Database\Validator\Permissions;
|
||||
use Utopia\Database\Validator\QueryValidator;
|
||||
@@ -23,6 +24,7 @@ use Utopia\Database\Validator\Structure;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Database\Exception\Authorization as AuthorizationException;
|
||||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\Limit as LimitException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Database\Validator\CustomId;
|
||||
@@ -1116,6 +1118,16 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
$count = $dbForInternal->count('indexes', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
|
||||
], 61);
|
||||
|
||||
$limit = 64 - MariaDB::getNumberOfDefaultIndexes();
|
||||
|
||||
if ($count >= $limit) {
|
||||
throw new Exception('Index limit exceeded', 400);
|
||||
}
|
||||
|
||||
// Convert Document[] to array of attribute metadata
|
||||
$oldAttributes = \array_map(function ($a) {
|
||||
return $a->getArrayCopy();
|
||||
@@ -1140,7 +1152,6 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
||||
$lengths[$key] = ($attributeType === Database::VAR_STRING) ? $attributeSize : null;
|
||||
}
|
||||
|
||||
// TODO@kodumbeats should $lengths be a part of the response model?
|
||||
try {
|
||||
$index = $dbForInternal->createDocument('indexes', new Document([
|
||||
'$id' => $collectionId.'_'.$indexId,
|
||||
@@ -1153,7 +1164,7 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
||||
'orders' => $orders,
|
||||
]));
|
||||
} catch (DuplicateException $th) {
|
||||
throw new Exception('Attribute already exists', 409);
|
||||
throw new Exception('Index already exists', 409);
|
||||
}
|
||||
|
||||
$dbForInternal->purgeDocument('collections', $collectionId);
|
||||
@@ -1571,8 +1582,11 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
catch (AuthorizationException $exception) {
|
||||
throw new Exception('Unauthorized permissions', 401);
|
||||
}
|
||||
catch (DuplicateException $exception) {
|
||||
throw new Exception('Document already exists', 409);
|
||||
}
|
||||
catch (StructureException $exception) {
|
||||
throw new Exception('Bad structure. '.$exception->getMessage(), 400);
|
||||
throw new Exception($exception->getMessage(), 400);
|
||||
}
|
||||
|
||||
$usage
|
||||
@@ -1645,4 +1659,4 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
;
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user