diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 4a5158799a..9d498deb8c 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -321,8 +321,6 @@ App::put('/v1/functions/:functionId') 'search' => implode(' ', [$functionId, $name, $function->getAttribute('runtime')]), ]))); - $dbForProject->deleteCachedDocument('functions', $function->getId()); - if ($next && $schedule !== $original) { // Async task reschedule $functionEvent = new Func(); @@ -389,8 +387,6 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId') 'scheduleNext' => (int)$next, ]))); - $dbForProject->deleteCachedDocument('functions', $function->getId()); - if ($next) { // Init first schedule $functionEvent = new Func(); $functionEvent @@ -772,8 +768,6 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId') ]))); } - $dbForProject->deleteCachedDocument('functions', $function->getId()); - $usage ->setParam('storage', $deployment->getAttribute('size', 0) * -1); @@ -917,9 +911,7 @@ App::post('/v1/functions/:functionId/executions') $vars = []; - $variables = $dbForProject->find('variables', [ - new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()]), - ], APP_LIMIT_COUNT); + $variables = $function['vars']; foreach ($variables as $variable) { $vars[$variable['key']] = $variable['value']; @@ -1197,9 +1189,7 @@ App::get('/v1/functions/:functionId/variables') throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND); } - $variables = $dbForProject->find('variables', [ - new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()]), - ], 5000); + $variables = $function['vars']; $response->dynamic(new Document([ 'variables' => $variables, @@ -1325,7 +1315,6 @@ App::delete('/v1/functions/:functionId/variables/:variableId') } $dbForProject->deleteDocument('variables', $variable->getId()); - $dbForProject->deleteCachedDocument('functions', $function->getId()); $response->noContent(); diff --git a/app/workers/builds.php b/app/workers/builds.php index fb64e61690..3074d7e274 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -145,9 +145,7 @@ class BuildsV1 extends Worker $source = $deployment->getAttribute('path'); $vars = []; - $variables = $dbForProject->find('variables', [ - new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()]) - ], 5000); + $variables = $function['vars']; foreach ($variables as $variable) { $vars[$variable['key']] = $variable['value']; @@ -187,8 +185,7 @@ class BuildsV1 extends Worker /** Set auto deploy */ if ($deployment->getAttribute('activate') === true) { $function->setAttribute('deployment', $deployment->getId()); - $function = $dbForProject->updateDocument('functions', $function->getId(), $function); - $dbForProject->deleteCachedDocument('functions', $function->getId()); + $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } /** Update function schedule */ @@ -197,7 +194,6 @@ class BuildsV1 extends Worker $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; $function->setAttribute('scheduleNext', (int)$next); $function = $dbForProject->updateDocument('functions', $function->getId(), $function); - $dbForProject->deleteCachedDocument('functions', $function->getId()); } catch (\Throwable $th) { $endtime = \time(); $build->setAttribute('endTime', $endtime); diff --git a/app/workers/functions.php b/app/workers/functions.php index a0ad9a0790..b3de9690fc 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -260,9 +260,7 @@ class FunctionsV1 extends Worker $vars = []; - $variables = $dbForProject->find('variables', [ - new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()]), - ], APP_LIMIT_COUNT); + $variables = $function['vars']; foreach ($variables as $variable) { $vars[$variable['key']] = $variable['value']; diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index 39808a7d45..60b2370dce 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -65,7 +65,7 @@ class Func extends Model 'type' => Response::MODEL_VARIABLE, 'description' => 'Function environment variables.', 'default' => [], - 'example' => new \stdClass(), + 'example' => [], 'array' => true ]) ->addRule('events', [ @@ -121,25 +121,4 @@ class Func extends Model { return Response::MODEL_FUNCTION; } - - /** - * Filter Function - * - * Automatically converts a [] default to a stdClass, this is called while grabbing the document. - * - * @param Document $document - * @return Document - */ - public function filter(Document $document): Document - { - $vars = $document->getAttribute('vars'); - if ($vars instanceof Document) { - $vars = $vars->getArrayCopy(); - } - - if (is_array($vars) && empty($vars)) { - $document->setAttribute('vars', new stdClass()); - } - return $document; - } }