logger moved to App::shutdown
This commit is contained in:
parent
0249966741
commit
eeca43014a
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
23
app/controllers/shared/cache.php
Normal file
23
app/controllers/shared/cache.php
Normal 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');
|
Loading…
Reference in a new issue