From fd2a2a45c63aafd19b58f2c657e87f027e2a4c9e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 8 Jul 2024 01:01:50 +0000 Subject: [PATCH 1/8] project collection accessed at attribute --- app/config/collections.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 72d126e343..8807f52ead 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -390,7 +390,7 @@ $commonCollections = [ '$id' => ID::custom('_key_email'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['email'], - 'lengths' => [256], + 'lengths' => [320], 'orders' => [Database::ORDER_ASC], ], [ @@ -996,7 +996,7 @@ $commonCollections = [ '$id' => ID::custom('_key_provider_providerUid'), 'type' => Database::INDEX_KEY, 'attributes' => ['provider', 'providerUid'], - 'lengths' => [128, 128], + 'lengths' => [100, 100], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ @@ -1120,14 +1120,14 @@ $commonCollections = [ '$id' => ID::custom('_key_userInternalId_provider_providerUid'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['userInternalId', 'provider', 'providerUid'], - 'lengths' => [11, 128, 128], + 'lengths' => [Database::LENGTH_KEY, 100, 385], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_provider_providerUid'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['provider', 'providerUid'], - 'lengths' => [128, 128], + 'lengths' => [100, 640], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ @@ -1148,7 +1148,7 @@ $commonCollections = [ '$id' => ID::custom('_key_provider'), 'type' => Database::INDEX_KEY, 'attributes' => ['provider'], - 'lengths' => [128], + 'lengths' => [100], 'orders' => [Database::ORDER_ASC], ], [ @@ -3068,7 +3068,7 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_name'), 'type' => Database::INDEX_KEY, 'attributes' => ['name'], - 'lengths' => [256], + 'lengths' => [768], 'orders' => [Database::ORDER_ASC], ], [ @@ -3117,7 +3117,7 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_runtime'), 'type' => Database::INDEX_KEY, 'attributes' => ['runtime'], - 'lengths' => [64], + 'lengths' => [768], 'orders' => [Database::ORDER_ASC], ], [ @@ -3857,14 +3857,14 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_trigger'), 'type' => Database::INDEX_KEY, 'attributes' => ['trigger'], - 'lengths' => [32], + 'lengths' => [128], 'orders' => [Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_status'), 'type' => Database::INDEX_KEY, 'attributes' => ['status'], - 'lengths' => [32], + 'lengths' => [128], 'orders' => [Database::ORDER_ASC], ], [ @@ -4421,6 +4421,17 @@ $consoleCollections = array_merge([ 'array' => false, 'filters' => [], ], + [ + '$id' => 'accessedAt', + 'type' => Database::VAR_DATETIME, + 'format' => '', + 'size' => 0, + 'signed' => false, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['datetime'], + ], ], 'indexes' => [ [ @@ -5833,14 +5844,14 @@ $bucketCollections = [ '$id' => ID::custom('_key_name'), 'type' => Database::INDEX_KEY, 'attributes' => ['name'], - 'lengths' => [256], + 'lengths' => [768], 'orders' => [Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_signature'), 'type' => Database::INDEX_KEY, 'attributes' => ['signature'], - 'lengths' => [256], + 'lengths' => [768], 'orders' => [Database::ORDER_ASC], ], [ From bfebf79630ca8464b50c717e22f54c3d11416eaf Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 8 Jul 2024 01:02:58 +0000 Subject: [PATCH 2/8] update project accessedAt once every 24 hours --- app/controllers/shared/api.php | 11 +++++++++++ app/init.php | 1 + 2 files changed, 12 insertions(+) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index bb9408e692..db4fd9ede7 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -715,6 +715,17 @@ App::shutdown() ->trigger(); } + /** + * Update project last activity + */ + if (!$project->isEmpty() && $project->getId() !== 'console') { + $accessedAt = $project->getAttribute('accessedAt', ''); + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_PROJECT_ACCESS)) > $accessedAt) { + $project->setAttribute('accessedAt', DateTime::now()); + Authorization::skip(fn () => $dbForConsole->updateDocument('projects', $project->getId(), $project)); + } + } + /** * Update user last activity */ diff --git a/app/init.php b/app/init.php index ea8b087faa..d3fb21e7ab 100644 --- a/app/init.php +++ b/app/init.php @@ -111,6 +111,7 @@ const APP_LIMIT_WRITE_RATE_PERIOD_DEFAULT = 60; // Default maximum write rate pe 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_USER_ACCCESS = 24 * 60 * 60; // 24 hours +const APP_PROJECT_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 4314; const APP_VERSION_STABLE = '1.5.7'; From cfb00bf2719d8be31a3090d218cf7f56b5122ae9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 8 Jul 2024 01:03:52 +0000 Subject: [PATCH 3/8] fix typo --- app/controllers/shared/api.php | 4 ++-- app/init.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Key.php | 2 +- src/Appwrite/Utopia/Response/Model/User.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index db4fd9ede7..279b660951 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -226,7 +226,7 @@ App::init() Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys. $accessedAt = $key->getAttribute('accessedAt', ''); - if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCCESS)) > $accessedAt) { + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCESS)) > $accessedAt) { $key->setAttribute('accessedAt', DateTime::now()); $dbForConsole->updateDocument('keys', $key->getId(), $key); $dbForConsole->purgeCachedDocument('projects', $project->getId()); @@ -731,7 +731,7 @@ App::shutdown() */ if (!$user->isEmpty()) { $accessedAt = $user->getAttribute('accessedAt', ''); - if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_USER_ACCCESS)) > $accessedAt) { + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_USER_ACCESS)) > $accessedAt) { $user->setAttribute('accessedAt', DateTime::now()); if (APP_MODE_ADMIN !== $mode) { diff --git a/app/init.php b/app/init.php index d3fb21e7ab..cc6e9683df 100644 --- a/app/init.php +++ b/app/init.php @@ -109,8 +109,8 @@ const APP_LIMIT_SUBSCRIBERS_SUBQUERY = 1_000_000; 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_USER_ACCCESS = 24 * 60 * 60; // 24 hours +const APP_KEY_ACCESS = 24 * 60 * 60; // 24 hours +const APP_USER_ACCESS = 24 * 60 * 60; // 24 hours const APP_PROJECT_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 4314; diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index 1179a73d62..1adab4417b 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -60,7 +60,7 @@ class Key extends Model ]) ->addRule('accessedAt', [ 'type' => self::TYPE_DATETIME, - 'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_KEY_ACCCESS / 60 / 60 . ' hours.', + 'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_KEY_ACCESS / 60 / 60 . ' hours.', 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE ]) diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 34e7c31621..672b8885a0 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -135,7 +135,7 @@ class User extends Model ]) ->addRule('accessedAt', [ 'type' => self::TYPE_DATETIME, - 'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_USER_ACCCESS / 60 / 60 . ' hours.', + 'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_USER_ACCESS / 60 / 60 . ' hours.', 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) From 61333908a5783f9f9ca821762a46803bec55fed4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 8 Jul 2024 01:11:09 +0000 Subject: [PATCH 4/8] set project accessed at while creating --- app/controllers/api/projects.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 91f19a2358..ee1cc947f6 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -20,6 +20,7 @@ use Utopia\Audit\Audit; use Utopia\Cache\Cache; use Utopia\Config\Config; use Utopia\Database\Database; +use Utopia\Database\DateTime as DatabaseDateTime; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Query as QueryException; @@ -167,6 +168,7 @@ App::post('/v1/projects') 'webhooks' => null, 'keys' => null, 'auths' => $auths, + 'accessedAt' => DatabaseDateTime::now(), 'search' => implode(' ', [$projectId, $name]), 'database' => $dsn, ])); From 4dd86da017b97659fdf56ae6a961dc52e844b327 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 9 Jul 2024 08:00:49 +0545 Subject: [PATCH 5/8] Update collections.php --- app/config/collections.php | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 8807f52ead..69d59b9af1 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -390,7 +390,7 @@ $commonCollections = [ '$id' => ID::custom('_key_email'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['email'], - 'lengths' => [320], + 'lengths' => [256], 'orders' => [Database::ORDER_ASC], ], [ @@ -996,7 +996,7 @@ $commonCollections = [ '$id' => ID::custom('_key_provider_providerUid'), 'type' => Database::INDEX_KEY, 'attributes' => ['provider', 'providerUid'], - 'lengths' => [100, 100], + 'lengths' => [128, 128], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ @@ -1120,14 +1120,14 @@ $commonCollections = [ '$id' => ID::custom('_key_userInternalId_provider_providerUid'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['userInternalId', 'provider', 'providerUid'], - 'lengths' => [Database::LENGTH_KEY, 100, 385], + 'lengths' => [11, 128, 128], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_provider_providerUid'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['provider', 'providerUid'], - 'lengths' => [100, 640], + 'lengths' => [128, 128], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ @@ -1148,7 +1148,7 @@ $commonCollections = [ '$id' => ID::custom('_key_provider'), 'type' => Database::INDEX_KEY, 'attributes' => ['provider'], - 'lengths' => [100], + 'lengths' => [128], 'orders' => [Database::ORDER_ASC], ], [ @@ -3068,7 +3068,7 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_name'), 'type' => Database::INDEX_KEY, 'attributes' => ['name'], - 'lengths' => [768], + 'lengths' => [256], 'orders' => [Database::ORDER_ASC], ], [ @@ -3117,7 +3117,7 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_runtime'), 'type' => Database::INDEX_KEY, 'attributes' => ['runtime'], - 'lengths' => [768], + 'lengths' => [64], 'orders' => [Database::ORDER_ASC], ], [ @@ -3857,14 +3857,14 @@ $projectCollections = array_merge([ '$id' => ID::custom('_key_trigger'), 'type' => Database::INDEX_KEY, 'attributes' => ['trigger'], - 'lengths' => [128], + 'lengths' => [32], 'orders' => [Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_status'), 'type' => Database::INDEX_KEY, 'attributes' => ['status'], - 'lengths' => [128], + 'lengths' => [32], 'orders' => [Database::ORDER_ASC], ], [ @@ -4311,6 +4311,17 @@ $consoleCollections = array_merge([ 'array' => false, 'filters' => [], ], + [ + '$id' => 'accessedAt', + 'type' => Database::VAR_DATETIME, + 'format' => '', + 'size' => 0, + 'signed' => false, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['datetime'], + ], [ '$id' => ID::custom('services'), 'type' => Database::VAR_STRING, @@ -4421,17 +4432,6 @@ $consoleCollections = array_merge([ 'array' => false, 'filters' => [], ], - [ - '$id' => 'accessedAt', - 'type' => Database::VAR_DATETIME, - 'format' => '', - 'size' => 0, - 'signed' => false, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => ['datetime'], - ], ], 'indexes' => [ [ @@ -5844,14 +5844,14 @@ $bucketCollections = [ '$id' => ID::custom('_key_name'), 'type' => Database::INDEX_KEY, 'attributes' => ['name'], - 'lengths' => [768], + 'lengths' => [256], 'orders' => [Database::ORDER_ASC], ], [ '$id' => ID::custom('_key_signature'), 'type' => Database::INDEX_KEY, 'attributes' => ['signature'], - 'lengths' => [768], + 'lengths' => [256], 'orders' => [Database::ORDER_ASC], ], [ From db3b2e6cb90af039aec069af4dc2bbbb2b895512 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 10 Jul 2024 07:22:13 +0000 Subject: [PATCH 6/8] composer update --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index e0e6628e43..cf3aaec13b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "06f391b62842a79736fe3fe77ec82adf", + "content-hash": "f5f5f624d7edf2e0a405f4669ae8f672", "packages": [ { "name": "adhocore/jwt", @@ -3157,16 +3157,16 @@ }, { "name": "laravel/pint", - "version": "v1.16.1", + "version": "v1.16.2", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "9266a47f1b9231b83e0cfd849009547329d871b1" + "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/9266a47f1b9231b83e0cfd849009547329d871b1", - "reference": "9266a47f1b9231b83e0cfd849009547329d871b1", + "url": "https://api.github.com/repos/laravel/pint/zipball/51f1ba679a6afe0315621ad143d788bd7ded0eca", + "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca", "shasum": "" }, "require": { @@ -3219,7 +3219,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-06-18T16:50:05+00:00" + "time": "2024-07-09T15:58:08+00:00" }, { "name": "matthiasmullie/minify", From 7ed877d96a2817d9445135889689d33dddae1289 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 15 Jul 2024 04:53:27 +0000 Subject: [PATCH 7/8] fix typo --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c719c07062..583a0160a1 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -270,7 +270,7 @@ App::init() Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys. $accessedAt = $key->getAttribute('accessedAt', ''); - if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCCESS)) > $accessedAt) { + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCESS)) > $accessedAt) { $key->setAttribute('accessedAt', DateTime::now()); $dbForConsole->updateDocument('keys', $key->getId(), $key); $dbForConsole->purgeCachedDocument('projects', $project->getId()); From 0374711298427cca4ea384fb78c695b07056013e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 16 Jul 2024 06:53:21 +0545 Subject: [PATCH 8/8] Update projects.php --- app/controllers/api/projects.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6f1e10d23f..af588fffc4 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -22,7 +22,7 @@ use Utopia\Audit\Audit; use Utopia\Cache\Cache; use Utopia\Config\Config; use Utopia\Database\Database; -use Utopia\Database\DateTime as DatabaseDateTime; +use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Query as QueryException; @@ -173,7 +173,7 @@ App::post('/v1/projects') 'webhooks' => null, 'keys' => null, 'auths' => $auths, - 'accessedAt' => DatabaseDateTime::now(), + 'accessedAt' => DateTime::now(), 'search' => implode(' ', [$projectId, $name]), 'database' => $dsn, ]));