From a7c0ef3d09627fcc1500f09ead612c80972be728 Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 6 Oct 2024 20:22:25 +0300 Subject: [PATCH 1/6] remove audits deletion --- app/controllers/api/databases.php | 4 ---- src/Appwrite/Platform/Workers/Databases.php | 17 ----------------- 2 files changed, 21 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 9c110647af..47a3468529 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3733,10 +3733,6 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu ) ); - $queueForDeletes - ->setType(DELETE_TYPE_AUDIT) - ->setDocument($document); - $queueForEvents ->setParam('databaseId', $databaseId) ->setParam('collectionId', $collection->getId()) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 56f5f012e8..128e997066 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -492,8 +492,6 @@ class Databases extends Action }); $dbForProject->deleteCollection('database_' . $database->getInternalId()); - - $this->deleteAuditLogsByResource('database/' . $database->getId(), $project, $dbForProject); } /** @@ -549,23 +547,8 @@ class Databases extends Action Query::equal('databaseInternalId', [$databaseInternalId]), Query::equal('collectionInternalId', [$collectionInternalId]) ], $dbForProject); - - $this->deleteAuditLogsByResource('database/' . $databaseId . '/collection/' . $collectionId, $project, $dbForProject); } - /** - * @param string $resource - * @param Document $project - * @param Database $dbForProject - * @return void - * @throws Exception - */ - protected function deleteAuditLogsByResource(string $resource, Document $project, Database $dbForProject): void - { - $this->deleteByGroup(Audit::COLLECTION, [ - Query::equal('resource', [$resource]) - ], $dbForProject); - } /** * @param string $collection collectionID From e06b77cf397c45b18d8de24093f51c3bbd90d7e7 Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 6 Oct 2024 20:25:51 +0300 Subject: [PATCH 2/6] remove audits deletion --- src/Appwrite/Platform/Workers/Databases.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 128e997066..f697e7be13 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -5,7 +5,6 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Event; use Appwrite\Messaging\Adapter\Realtime; use Exception; -use Utopia\Audit\Audit; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; From 424f24af04eeea8434788fcde5da559718499d90 Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 6 Oct 2024 21:02:24 +0300 Subject: [PATCH 3/6] remove resource --- app/controllers/api/databases.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 47a3468529..72e3c6d464 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3656,11 +3656,10 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu ->inject('requestTimestamp') ->inject('response') ->inject('dbForProject') - ->inject('queueForDeletes') ->inject('queueForEvents') ->inject('queueForUsage') ->inject('mode') - ->action(function (string $databaseId, string $collectionId, string $documentId, ?\DateTime $requestTimestamp, Response $response, Database $dbForProject, Delete $queueForDeletes, Event $queueForEvents, Usage $queueForUsage, string $mode) { + ->action(function (string $databaseId, string $collectionId, string $documentId, ?\DateTime $requestTimestamp, Response $response, Database $dbForProject, Event $queueForEvents, Usage $queueForUsage, string $mode) { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); $isAPIKey = Auth::isAppUser(Authorization::getRoles()); From fa513d62429c6cd8b4de88f013e415f144e9518c Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 7 Oct 2024 11:06:08 +0300 Subject: [PATCH 4/6] debug --- app/controllers/api/projects.php | 15 +++++++++++++++ app/controllers/general.php | 6 ++++++ app/controllers/shared/api.php | 22 +++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 934793410b..ca5d522e37 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -88,7 +88,11 @@ App::post('/v1/projects') ->inject('hooks') ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Request $request, Response $response, Database $dbForConsole, Cache $cache, Group $pools, Hooks $hooks) { + $ctime = time(); + var_dump("[".$region."] - Before getDocument('teams')"); $team = $dbForConsole->getDocument('teams', $teamId); + $diff = time() - $ctime; + var_dump("[".$region."] - After getDocument('teams') : " . $diff . " sec"); if ($team->isEmpty()) { throw new Exception(Exception::TEAM_NOT_FOUND); @@ -145,6 +149,8 @@ App::post('/v1/projects') } try { + $ctime = time(); + var_dump("[".$region."] - Before createDocument('projects')"); $project = $dbForConsole->createDocument('projects', new Document([ '$id' => $projectId, '$permissions' => [ @@ -178,6 +184,10 @@ App::post('/v1/projects') 'search' => implode(' ', [$projectId, $name]), 'database' => $dsn, ])); + + $diff = time() - $ctime; + var_dump("[".$region."] - After createDocument('projects') : " . $diff . " sec"); + } catch (Duplicate) { throw new Exception(Exception::PROJECT_ALREADY_EXISTS); } @@ -229,7 +239,12 @@ App::post('/v1/projects') }, $collection['indexes']); try { + + $ctime = time(); + var_dump("[".$region."] - Before createCollection('".$key."')"); $dbForProject->createCollection($key, $attributes, $indexes); + $diff = time() - $ctime; + var_dump("[".$region."] - After createCollection('".$key."') : " . $diff . " sec"); } catch (Duplicate) { // Collection already exists } diff --git a/app/controllers/general.php b/app/controllers/general.php index 04554a940e..ecaf066176 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -451,6 +451,9 @@ App::init() ->inject('queueForEvents') ->inject('queueForCertificates') ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Document $console, Document $project, Database $dbForConsole, callable $getProjectDB, Locale $locale, array $localeCodes, array $clients, Reader $geodb, Usage $queueForUsage, Event $queueForEvents, Certificate $queueForCertificates) { + $ctime = time(); + var_dump("[".$region."] - Before general first init hook"); + /* * Appwrite Router */ @@ -655,6 +658,9 @@ App::init() ) { throw new AppwriteException(AppwriteException::GENERAL_UNKNOWN_ORIGIN, $originValidator->getDescription()); } + + $diff = time() - $ctime; + var_dump("[".$region."] - After general first init hook : " . $diff . " sec"); }); App::options() diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f0d896c95a..f72672a357 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -162,6 +162,9 @@ App::init() ->inject('mode') ->inject('team') ->action(function (App $utopia, Request $request, Database $dbForConsole, Document $project, Document $user, ?Document $session, array $servers, string $mode, Document $team) { + $ctime = time(); + var_dump("[".$region."] - Before shared api first init hook"); + $route = $utopia->getRoute(); if ($project->isEmpty()) { @@ -344,6 +347,8 @@ App::init() throw new Exception(Exception::USER_MORE_FACTORS_REQUIRED); } } + $diff = time() - $ctime; + var_dump("[".$region."] - After shared api first init hook : " . $diff . " sec"); }); App::init() @@ -363,7 +368,8 @@ App::init() ->inject('dbForProject') ->inject('mode') ->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $queueForEvents, Messaging $queueForMessaging, Audit $queueForAudits, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Usage $queueForUsage, Database $dbForProject, string $mode) use ($databaseListener) { - + $ctime = time(); + var_dump("[".$region."] - Before shared api second init hook"); $route = $utopia->getRoute(); if ( @@ -521,6 +527,8 @@ App::init() ; } } + $diff = time() - $ctime; + var_dump("[".$region."] - After shared api first init hook : " . $diff . " sec"); }); App::init() @@ -551,6 +559,10 @@ App::shutdown() ->inject('project') ->inject('dbForProject') ->action(function (App $utopia, Request $request, Response $response, Document $project, Database $dbForProject) { + $ctime = time(); + var_dump("[".$region."] - Before shared api first shutdown hook"); + $route = $utopia->getRoute(); + $sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT; $session = $response->getPayload(); $userId = $session['userId'] ?? ''; @@ -575,6 +587,8 @@ App::shutdown() } $dbForProject->purgeCachedDocument('users', $userId); + $diff = time() - $ctime; + var_dump("[".$region."] - After shared api first shutdown hook : " . $diff . " sec"); }); App::shutdown() @@ -597,6 +611,10 @@ App::shutdown() ->inject('dbForConsole') ->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $queueForEvents, Audit $queueForAudits, Usage $queueForUsage, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Messaging $queueForMessaging, Database $dbForProject, Func $queueForFunctions, string $mode, Database $dbForConsole) use ($parseLabel) { + $ctime = time(); + var_dump("[".$region."] - Before shared api second shutdown hook"); + $route = $utopia->getRoute(); + $responsePayload = $response->getPayload(); if (!empty($queueForEvents->getEvent())) { @@ -798,6 +816,8 @@ App::shutdown() } } } + $diff = time() - $ctime; + var_dump("[".$region."] - After shared api second shutdown hook : " . $diff . " sec"); }); App::init() From 4590ae11ee4df4761667968210a2210c412429a6 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 7 Oct 2024 13:57:02 +0300 Subject: [PATCH 5/6] revert last commit --- app/controllers/api/projects.php | 15 --------------- app/controllers/general.php | 6 ------ app/controllers/shared/api.php | 22 +--------------------- 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index ca5d522e37..934793410b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -88,11 +88,7 @@ App::post('/v1/projects') ->inject('hooks') ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Request $request, Response $response, Database $dbForConsole, Cache $cache, Group $pools, Hooks $hooks) { - $ctime = time(); - var_dump("[".$region."] - Before getDocument('teams')"); $team = $dbForConsole->getDocument('teams', $teamId); - $diff = time() - $ctime; - var_dump("[".$region."] - After getDocument('teams') : " . $diff . " sec"); if ($team->isEmpty()) { throw new Exception(Exception::TEAM_NOT_FOUND); @@ -149,8 +145,6 @@ App::post('/v1/projects') } try { - $ctime = time(); - var_dump("[".$region."] - Before createDocument('projects')"); $project = $dbForConsole->createDocument('projects', new Document([ '$id' => $projectId, '$permissions' => [ @@ -184,10 +178,6 @@ App::post('/v1/projects') 'search' => implode(' ', [$projectId, $name]), 'database' => $dsn, ])); - - $diff = time() - $ctime; - var_dump("[".$region."] - After createDocument('projects') : " . $diff . " sec"); - } catch (Duplicate) { throw new Exception(Exception::PROJECT_ALREADY_EXISTS); } @@ -239,12 +229,7 @@ App::post('/v1/projects') }, $collection['indexes']); try { - - $ctime = time(); - var_dump("[".$region."] - Before createCollection('".$key."')"); $dbForProject->createCollection($key, $attributes, $indexes); - $diff = time() - $ctime; - var_dump("[".$region."] - After createCollection('".$key."') : " . $diff . " sec"); } catch (Duplicate) { // Collection already exists } diff --git a/app/controllers/general.php b/app/controllers/general.php index ecaf066176..04554a940e 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -451,9 +451,6 @@ App::init() ->inject('queueForEvents') ->inject('queueForCertificates') ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Document $console, Document $project, Database $dbForConsole, callable $getProjectDB, Locale $locale, array $localeCodes, array $clients, Reader $geodb, Usage $queueForUsage, Event $queueForEvents, Certificate $queueForCertificates) { - $ctime = time(); - var_dump("[".$region."] - Before general first init hook"); - /* * Appwrite Router */ @@ -658,9 +655,6 @@ App::init() ) { throw new AppwriteException(AppwriteException::GENERAL_UNKNOWN_ORIGIN, $originValidator->getDescription()); } - - $diff = time() - $ctime; - var_dump("[".$region."] - After general first init hook : " . $diff . " sec"); }); App::options() diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f72672a357..f0d896c95a 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -162,9 +162,6 @@ App::init() ->inject('mode') ->inject('team') ->action(function (App $utopia, Request $request, Database $dbForConsole, Document $project, Document $user, ?Document $session, array $servers, string $mode, Document $team) { - $ctime = time(); - var_dump("[".$region."] - Before shared api first init hook"); - $route = $utopia->getRoute(); if ($project->isEmpty()) { @@ -347,8 +344,6 @@ App::init() throw new Exception(Exception::USER_MORE_FACTORS_REQUIRED); } } - $diff = time() - $ctime; - var_dump("[".$region."] - After shared api first init hook : " . $diff . " sec"); }); App::init() @@ -368,8 +363,7 @@ App::init() ->inject('dbForProject') ->inject('mode') ->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $queueForEvents, Messaging $queueForMessaging, Audit $queueForAudits, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Usage $queueForUsage, Database $dbForProject, string $mode) use ($databaseListener) { - $ctime = time(); - var_dump("[".$region."] - Before shared api second init hook"); + $route = $utopia->getRoute(); if ( @@ -527,8 +521,6 @@ App::init() ; } } - $diff = time() - $ctime; - var_dump("[".$region."] - After shared api first init hook : " . $diff . " sec"); }); App::init() @@ -559,10 +551,6 @@ App::shutdown() ->inject('project') ->inject('dbForProject') ->action(function (App $utopia, Request $request, Response $response, Document $project, Database $dbForProject) { - $ctime = time(); - var_dump("[".$region."] - Before shared api first shutdown hook"); - $route = $utopia->getRoute(); - $sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT; $session = $response->getPayload(); $userId = $session['userId'] ?? ''; @@ -587,8 +575,6 @@ App::shutdown() } $dbForProject->purgeCachedDocument('users', $userId); - $diff = time() - $ctime; - var_dump("[".$region."] - After shared api first shutdown hook : " . $diff . " sec"); }); App::shutdown() @@ -611,10 +597,6 @@ App::shutdown() ->inject('dbForConsole') ->action(function (App $utopia, Request $request, Response $response, Document $project, Document $user, Event $queueForEvents, Audit $queueForAudits, Usage $queueForUsage, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Messaging $queueForMessaging, Database $dbForProject, Func $queueForFunctions, string $mode, Database $dbForConsole) use ($parseLabel) { - $ctime = time(); - var_dump("[".$region."] - Before shared api second shutdown hook"); - $route = $utopia->getRoute(); - $responsePayload = $response->getPayload(); if (!empty($queueForEvents->getEvent())) { @@ -816,8 +798,6 @@ App::shutdown() } } } - $diff = time() - $ctime; - var_dump("[".$region."] - After shared api second shutdown hook : " . $diff . " sec"); }); App::init() From 24283dff7f7237f5c361e2cf31e54b8ced028553 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 9 Oct 2024 10:13:49 +0300 Subject: [PATCH 6/6] removed audit deletion leftovers in deletes worker --- src/Appwrite/Platform/Workers/Deletes.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 62fd8cd177..48e4014f1e 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -119,10 +119,6 @@ class Deletes extends Action if (!$project->isEmpty()) { $this->deleteAuditLogs($project, $getProjectDB, $auditRetention); } - - if (!$document->isEmpty()) { - $this->deleteAuditLogsByResource($getProjectDB, 'document/' . $document->getId(), $project); - } break; case DELETE_TYPE_ABUSE: $this->deleteAbuseLogs($project, $getProjectDB, $abuseRetention); @@ -733,22 +729,6 @@ class Deletes extends Action } } - /** - * @param callable $getProjectDB - * @param string $resource - * @param Document $project - * @return void - * @throws Exception - */ - private function deleteAuditLogsByResource(callable $getProjectDB, string $resource, Document $project): void - { - $dbForProject = $getProjectDB($project); - - $this->deleteByGroup(Audit::COLLECTION, [ - Query::equal('resource', [$resource]) - ], $dbForProject); - } - /** * @param callable $getProjectDB * @param Device $deviceForFunctions