From edecd8dc222ebc90e1109c22cb3faf538472f3f8 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 15 Aug 2022 13:52:20 +0300 Subject: [PATCH] some fixes --- app/controllers/shared/api.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 821f0067ee..1635f0a4a9 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -335,16 +335,15 @@ App::shutdown() return $label; }; - $useCache = $route->getLabel('cache', false); - if ($useCache) { + $useCache = $route->getLabel('cache', false); + if ($useCache) { $resource = null; $data = $response->getPayload(); - if (!empty($data['payload'])) { - - $pattern = $route->getLabel('cache.resource', null); - if (!empty($pattern)) { - $resource = $parseLabel($pattern); - } + if (!empty($data['payload'])) { + $pattern = $route->getLabel('cache.resource', null); + if (!empty($pattern)) { + $resource = $parseLabel($pattern); + } $key = md5($request->getURI() . implode('*', $request->getParams())); @@ -354,33 +353,33 @@ App::shutdown() ]) ; $signature = md5($data); - $cacheLog = $dbForProject->getDocument('cache', $key); - if ($cacheLog->isEmpty()) { - Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([ + $cacheLog = $dbForProject->getDocument('cache', $key); + if ($cacheLog->isEmpty()) { + Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([ '$id' => $key, 'resource' => $resource, 'accessedAt' => \time(), 'signature' => $signature, ]))); - } elseif (date('Y/m/d', \time()) > date('Y/m/d', $cacheLog->getAttribute('accessedAt'))) { + } elseif (date('Y/m/d', \time()) > date('Y/m/d', $cacheLog->getAttribute('accessedAt'))) { $cacheLog->setAttribute('accessedAt', \time()); Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); - } + } $cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())); $cache->save($key, $data); - } } + } - if ( + if ( App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled' && $project->getId() && $mode !== APP_MODE_ADMIN // TODO: add check to make sure user is admin && !empty($route->getLabel('sdk.namespace', null)) - ) { // Don't calculate console usage on admin mode + ) { // Don't calculate console usage on admin mode $usage ->setParam('networkRequestSize', $request->getSize() + $usage->getParam('storage')) ->setParam('networkResponseSize', $response->getSize()) ->submit(); - } + } });