1
0
Fork 0
mirror of synced 2024-10-03 19:53:33 +13:00

change to use findOne instead of iterating index array

This commit is contained in:
Prateek Banga 2023-07-19 14:04:35 +05:30
parent 9fafd39fef
commit 131e9658a5

View file

@ -2535,20 +2535,18 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes/:key')
throw new Exception(Exception::COLLECTION_NOT_FOUND);
}
$indexes = $collection->getAttribute('indexes');
// Search for index
$indexIndex = array_search($key, array_map(fn($idx) => $idx['key'], $indexes));
if ($indexIndex === false) {
$index = $dbForProject->findOne('indexes', [
Query::equal('$id',[$database->getInternalId().'_'.$collection->getInternalId().'_'.$key])
]);
if ($index->isEmpty()) {
throw new Exception(Exception::INDEX_NOT_FOUND);
}
$index = $indexes[$indexIndex];
$index->setAttribute('collectionId', $database->getInternalId() . '_' . $collectionId);
$response->dynamic($index, Response::MODEL_INDEX);
});
});;
App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key')
->alias('/v1/database/collections/:collectionId/indexes/:key', ['databaseId' => 'default'])