1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00

logger moved to App::shutdown

This commit is contained in:
shimon 2022-07-07 18:45:24 +03:00
parent 0249966741
commit eeca43014a
3 changed files with 24 additions and 18 deletions

View file

@ -612,6 +612,7 @@ App::get('/.well-known/acme-challenge')
});
include_once __DIR__ . '/shared/api.php';
include_once __DIR__ . '/shared/cache.php';
include_once __DIR__ . '/shared/web.php';
foreach (Config::getParam('services', []) as $service) {

View file

@ -239,24 +239,6 @@ App::shutdown(function (App $utopia, Request $request, Response $response, Docum
$route = $utopia->match($request);
$groups = $route->getGroups();
if (in_array('cache', $groups)) {
if (!empty($cacheKey) && !empty($cachePath)) {
$cacheLog = $dbForProject->getDocument('cache', $cacheKey);
if ($cacheLog->isEmpty()) {
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
'$id' => $cacheKey,
'accessedAt' => time(),
'path' => $cachePath
])));
} else {
$cacheLog->setAttribute('accessedAt', time());
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}
}
}
if (
App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled'
&& $project->getId()

View file

@ -0,0 +1,23 @@
<?php
use Utopia\App;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
App::shutdown(function (Database $dbForProject, string $cacheKey, string $cachePath) {
if (!empty($cacheKey) && !empty($cachePath)) {
$cacheLog = $dbForProject->getDocument('cache', $cacheKey);
if ($cacheLog->isEmpty()) {
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
'$id' => $cacheKey,
'accessedAt' => time(),
'path' => $cachePath
])));
} else {
$cacheLog->setAttribute('accessedAt', time());
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}
}
}, ['dbForProject', 'cacheKey', 'cachePath'], 'cache');