From 65883122e3ff2e4a8094f669e61db449b8058c31 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 4 Jan 2026 12:16:59 +0200 Subject: [PATCH 1/3] rules changes --- app/config/collections/platform.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index e919df8e1a..d5e7ff4669 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -1402,21 +1402,21 @@ $platformCollections = [ '$id' => '_key_type', 'type' => Database::INDEX_KEY, 'attributes' => ['type'], - 'lengths' => [32], + 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ '$id' => '_key_trigger', 'type' => Database::INDEX_KEY, 'attributes' => ['trigger'], - 'lengths' => [32], + 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ '$id' => '_key_deploymentResourceType', 'type' => Database::INDEX_KEY, 'attributes' => ['deploymentResourceType'], - 'lengths' => [32], + 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ @@ -1458,23 +1458,30 @@ $platformCollections = [ '$id' => ID::custom('_key_owner'), 'type' => Database::INDEX_KEY, 'attributes' => ['owner'], - 'lengths' => [16], + 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_region'), 'type' => Database::INDEX_KEY, 'attributes' => ['region'], - 'lengths' => [16], + 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => ID::custom('_key_piid_riid_rt'), + '$id' => ID::custom('_key_piid_diid_drt'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectInternalId', 'deploymentInternalId', 'deploymentResourceType'], 'lengths' => [], 'orders' => [], ], + [ + '$id' => '_key_region_status_createdAt', + 'type' => Database::INDEX_KEY, + 'attributes' => ['region', 'status', '$createdAt'], + 'lengths' => [], + 'orders' => [], + ], ], ], From b6aeaffe8be392922c99d865136ecb0f5b70094b Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 4 Jan 2026 12:20:22 +0200 Subject: [PATCH 2/3] Remove region index --- app/config/collections/platform.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index d5e7ff4669..57f0a0ae7b 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -1461,13 +1461,6 @@ $platformCollections = [ 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], - [ - '$id' => ID::custom('_key_region'), - 'type' => Database::INDEX_KEY, - 'attributes' => ['region'], - 'lengths' => [], - 'orders' => [Database::ORDER_ASC], - ], [ '$id' => ID::custom('_key_piid_diid_drt'), 'type' => Database::INDEX_KEY, From 3b5b15d1a6509115cc631901478577d2f73a41ae Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Tue, 6 Jan 2026 17:49:32 +0530 Subject: [PATCH 3/3] Remove dual read for `keys` (#11083) * Remove dual read for `keys` * write to mock * remove dual writes * Revert "remove dual writes" This reverts commit ce9a48423b01b012620c4485654332edb3d62b2d. * add todo --- app/controllers/api/projects.php | 37 +++++-------------- app/controllers/mock.php | 4 ++ app/init/database/filters.php | 9 +---- src/Appwrite/Platform/Workers/Deletes.php | 9 +---- .../Platform/Workers/StatsResources.php | 9 +---- 5 files changed, 19 insertions(+), 49 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 40bde3baf3..74f734a856 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1501,6 +1501,7 @@ App::post('/v1/projects/:projectId/keys') Permission::update(Role::any()), Permission::delete(Role::any()), ], + // TODO: @hmacr Remove `projectInternalId` and `projectId` column writes before deleting the column. 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'resourceInternalId' => $project->getSequence(), @@ -1553,13 +1554,8 @@ App::get('/v1/projects/:projectId/keys') } $keys = $dbForPlatform->find('keys', [ - Query::or([ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$project->getSequence()]), - ]) - ]), + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), Query::limit(5000), ]); @@ -1600,13 +1596,8 @@ App::get('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::or([ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$project->getSequence()]), - ]) - ]) + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { @@ -1650,13 +1641,8 @@ App::put('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::or([ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$project->getSequence()]), - ]) - ]) + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { @@ -1707,13 +1693,8 @@ App::delete('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::or([ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$project->getSequence()]), - ]) - ]) + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 6f092a5d19..fd7dae55b4 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -200,8 +200,12 @@ App::post('/v1/mock/api-key-unprefixed') Permission::update(Role::any()), Permission::delete(Role::any()), ], + // TODO: @hmacr Remove `projectInternalId` and `projectId` column writes before deleting the column. 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), + 'resourceInternalId' => $project->getSequence(), + 'resourceId' => $project->getId(), + 'resourceType' => 'projects', 'name' => 'Outdated key', 'scopes' => $scopes, 'expire' => null, diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 49c13c9a0b..c9ad3fce03 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -136,13 +136,8 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('keys', [ - Query::or([ - Query::equal('projectInternalId', [$document->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$document->getSequence()]), - ]) - ]), + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index dbe1882294..983e13b295 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -568,13 +568,8 @@ class Deletes extends Action // Delete Keys $this->deleteByGroup('keys', [ - Query::or([ - Query::equal('projectInternalId', [$projectInternalId]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$projectInternalId]), - ]) - ]), + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$projectInternalId]), Query::orderAsc() ], $dbForPlatform); diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 967dbc59a4..1c3db8d9c9 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -111,13 +111,8 @@ class StatsResources extends Action Query::equal('projectInternalId', [$project->getSequence()]) ]); $keys = $dbForPlatform->count('keys', [ - Query::or([ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::and([ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$project->getSequence()]), - ]) - ]), + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$project->getSequence()]), ]); $domains = $dbForPlatform->count('rules', [