From d0abbd9fc30f9bee69c34b01c237900ce2abf9b7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Feb 2022 14:16:15 +0400 Subject: [PATCH] feat: disable authorization in deletes worker --- app/controllers/api/functions.php | 1 - app/workers/deletes.php | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 6290abd81e..fdb075daee 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -368,7 +368,6 @@ App::patch('/v1/functions/:functionId/deployment') $function = $dbForProject->getDocument('functions', $functionId); $deployment = $dbForProject->getDocument('deployments', $deployment); - var_dump($deployment); $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', '')); if ($function->isEmpty()) { diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 7e46325cc3..0449ed0d91 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -14,6 +14,8 @@ use Utopia\Audit\Audit; require_once __DIR__ . '/../init.php'; +Authorization::disable(); + Console::title('Deletes V1 Worker'); Console::success(APP_NAME . ' deletes worker v1 has started' . "\n"); @@ -206,7 +208,7 @@ class DeletesV1 extends Worker ], $this->getProjectDB($projectId)); $user->setAttribute('sessions', []); - $updated = Authorization::skip(fn() => $this->getProjectDB($projectId)->updateDocument('users', $userId, $user)); + $updated = $this->getProjectDB($projectId)->updateDocument('users', $userId, $user); // Delete Memberships and decrement team membership counts $this->deleteByGroup('memberships', [ @@ -456,8 +458,6 @@ class DeletesV1 extends Worker */ protected function deleteById(Document $document, Database $database, callable $callback = null): bool { - Authorization::disable(); - if ($database->deleteDocument($document->getCollection(), $document->getId())) { Console::success('Deleted document "' . $document->getId() . '" successfully'); @@ -470,8 +470,6 @@ class DeletesV1 extends Worker Console::error('Failed to delete document: ' . $document->getId()); return false; } - - Authorization::reset(); } /** @@ -488,7 +486,7 @@ class DeletesV1 extends Worker $executionStart = \microtime(true); while ($sum === $limit) { - $projects = Authorization::skip(fn() => $this->getConsoleDB()->find('projects', [], $limit, ($chunk * $limit))); + $projects = $this->getConsoleDB()->find('projects', [], $limit, ($chunk * $limit)); $chunk++; @@ -527,12 +525,8 @@ class DeletesV1 extends Worker while ($sum === $limit) { $chunk++; - Authorization::disable(); - $results = $database->find($collection, $queries, $limit, 0); - Authorization::reset(); - $sum = count($results); Console::info('Deleting chunk #' . $chunk . '. Found ' . $sum . ' documents');