From 02cd8720f78273626e97c36eafbbb544f95748ba Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 31 May 2023 14:06:25 -0700 Subject: [PATCH 1/5] Don't clear cache on startup --- app/http.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/http.php b/app/http.php index 23fd0dbcc9..2978eee51f 100644 --- a/app/http.php +++ b/app/http.php @@ -89,7 +89,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { try { $cache = $app->getResource('cache'); /** @var Utopia\Cache\Cache $cache */ - $cache->flush(); Console::success('[Setup] - Creating database: appwrite...'); $dbForConsole->create(); } catch (\Exception $e) { From 2ee7a3a35698ff5696af2a7dded863103577db8a Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 31 May 2023 16:02:46 -0700 Subject: [PATCH 2/5] Prevent triggering a function off of a function --- src/Appwrite/Event/Validator/Event.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Validator/Event.php b/src/Appwrite/Event/Validator/Event.php index 4bf501f2d3..c67d60055b 100644 --- a/src/Appwrite/Event/Validator/Event.php +++ b/src/Appwrite/Event/Validator/Event.php @@ -7,6 +7,11 @@ use Utopia\Validator; class Event extends Validator { + /** + * @var string + */ + protected string $message = 'Event is not valid.'; + /** * Get Description. * @@ -16,7 +21,7 @@ class Event extends Validator */ public function getDescription(): string { - return 'Event is not valid.'; + return $this->message; } /** @@ -40,6 +45,12 @@ class Event extends Validator * Identify all sections of the pattern. */ $type = $parts[0] ?? false; + + if ($type == 'functions') { + $this->message = 'Triggering a function on a function event is not allowed.'; + return false; + } + $resource = $parts[1] ?? false; $hasSubResource = $count > 3 && ($events[$type]['$resource'] ?? false) && ($events[$type][$parts[2]]['$resource'] ?? false); $hasSubSubResource = $count > 5 && $hasSubResource && ($events[$type][$parts[2]][$parts[4]]['$resource'] ?? false); From 23e6c1adf60b4cdc395b53efd4baaa697ae83df8 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 2 Jun 2023 17:19:00 +0530 Subject: [PATCH 3/5] feat: remove unused orderBy, skip executing recursive functions --- app/console | 2 +- app/workers/functions.php | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/console b/app/console index 3a0c8f0334..9174d8f8cb 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 3a0c8f0334d402a6e27c8b5c0512f3d60080ddbd +Subproject commit 9174d8f8cb584744dd7a53f69d324f490ee82ee3 diff --git a/app/workers/functions.php b/app/workers/functions.php index e5542c9834..beed27018f 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -265,8 +265,7 @@ $server->job() while ($sum >= $limit) { $functions = $dbForProject->find('functions', [ Query::limit($limit), - Query::offset($offset), - Query::orderAsc('name'), + Query::offset($offset) ]); $sum = \count($functions); @@ -278,7 +277,15 @@ $server->job() if (!array_intersect($events, $function->getAttribute('events', []))) { continue; } - Console::success('Iterating function: ' . $function->getAttribute('name')); + + /** Skip if a function has been triggered by its own execution */ + $event = "functions.{$function->getId()}.executions.*"; + if(in_array($event, $events)) { + Console::warning("Skipping function: {$function->getAttribute('name')} from project: {$project->getId()} triggered by self"); + continue; + } + + Console::success("Iterating function: {$function->getAttribute('name')} from project: {$project->getId()}"); $execute( log: $log, statsd: $statsd, From fac4b6f6002520288535938312724dbc56bc4123 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 2 Jun 2023 17:20:08 +0530 Subject: [PATCH 4/5] fix: update console --- app/console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console b/app/console index 9174d8f8cb..b981302dee 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 9174d8f8cb584744dd7a53f69d324f490ee82ee3 +Subproject commit b981302dee30eab33e155af79f0088822b29a2b6 From 36f1791a929dc34477636dfd95393bf2a75012be Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 2 Jun 2023 17:59:20 +0530 Subject: [PATCH 5/5] chore: linter --- app/workers/functions.php | 2 +- src/Appwrite/Event/Validator/Event.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/workers/functions.php b/app/workers/functions.php index beed27018f..705d8e06ab 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -280,7 +280,7 @@ $server->job() /** Skip if a function has been triggered by its own execution */ $event = "functions.{$function->getId()}.executions.*"; - if(in_array($event, $events)) { + if (in_array($event, $events)) { Console::warning("Skipping function: {$function->getAttribute('name')} from project: {$project->getId()} triggered by self"); continue; } diff --git a/src/Appwrite/Event/Validator/Event.php b/src/Appwrite/Event/Validator/Event.php index c67d60055b..3f22900486 100644 --- a/src/Appwrite/Event/Validator/Event.php +++ b/src/Appwrite/Event/Validator/Event.php @@ -45,7 +45,7 @@ class Event extends Validator * Identify all sections of the pattern. */ $type = $parts[0] ?? false; - + if ($type == 'functions') { $this->message = 'Triggering a function on a function event is not allowed.'; return false;