From 44e3851f5e44b6a3561d4716df881e73c9e3b55f Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 15 Jun 2022 15:57:06 +0300 Subject: [PATCH 1/2] Adding Internal Ids to Database Api --- app/config/collections.php | 36 ++++++++++++++++++++++++++++++++ app/controllers/api/database.php | 7 +++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index e87e2a4b9..5945374fe 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -119,6 +119,17 @@ $collections = [ '$id' => 'attributes', 'name' => 'Attributes', 'attributes' => [ + [ + '$id' => 'collectionInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'collectionId', 'type' => Database::VAR_STRING, @@ -248,6 +259,13 @@ $collections = [ ], ], 'indexes' => [ + [ + '$id' => '_key_collection_internal_id', + 'type' => Database::INDEX_KEY, + 'attributes' => ['collectionInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], [ '$id' => '_key_collection', 'type' => Database::INDEX_KEY, @@ -263,6 +281,17 @@ $collections = [ '$id' => 'indexes', 'name' => 'Indexes', 'attributes' => [ + [ + '$id' => 'collectionInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'collectionId', 'type' => Database::VAR_STRING, @@ -349,6 +378,13 @@ $collections = [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => '_key_collection_internal_id', + 'type' => Database::INDEX_KEY, + 'attributes' => ['collectionInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], ], ], diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 358da9a52..4904dadea 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -47,6 +47,7 @@ use MaxMind\Db\Reader; * * * @return Document Newly created attribute document + * @throws Exception */ function createAttribute(string $collectionId, Document $attribute, Response $response, Database $dbForProject, EventDatabase $database, EventAudit $audits, Event $events, Stats $usage): Document { @@ -86,6 +87,7 @@ function createAttribute(string $collectionId, Document $attribute, Response $re $attribute = new Document([ '$id' => $collectionId . '_' . $key, 'key' => $key, + 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck @@ -1263,8 +1265,8 @@ App::post('/v1/database/collections/:collectionId/indexes') } $count = $dbForProject->count('indexes', [ - new Query('collectionId', Query::TYPE_EQUAL, [$collectionId]) - ], 61); + new Query('collectionInternalId', Query::TYPE_EQUAL, [$collection->getInternalId()]) + ]); $limit = 64 - MariaDB::getNumberOfDefaultIndexes(); @@ -1304,6 +1306,7 @@ App::post('/v1/database/collections/:collectionId/indexes') '$id' => $collectionId . '_' . $key, 'key' => $key, 'status' => 'processing', // processing, available, failed, deleting, stuck + 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, 'attributes' => $attributes, From 6d7580b9d0a2e30b91900402fae1b46587d7cbb2 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 16 Jun 2022 10:53:57 +0300 Subject: [PATCH 2/2] subQueryIndexes, subQueryAttributes with new relations --- app/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/init.php b/app/init.php index faf21a8e1..22897168b 100644 --- a/app/init.php +++ b/app/init.php @@ -256,7 +256,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('attributes', [ - new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()]) + new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()]) ], $database->getAttributeLimit()); } ); @@ -269,7 +269,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('indexes', [ - new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()]) + new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()]) ], 64); } );