small fix
This commit is contained in:
parent
65011d1af7
commit
56a21b3968
5 changed files with 43 additions and 41 deletions
2
.env
2
.env
|
@ -71,7 +71,7 @@ _APP_FUNCTIONS_INACTIVE_THRESHOLD=60
|
|||
OPEN_RUNTIMES_NETWORK=appwrite_runtimes
|
||||
_APP_EXECUTOR_SECRET=your-secret-key
|
||||
_APP_EXECUTOR_HOST=http://appwrite-executor/v1
|
||||
_APP_MAINTENANCE_INTERVAL=2592000
|
||||
_APP_MAINTENANCE_INTERVAL=86400
|
||||
_APP_MAINTENANCE_RETENTION_CACHE=2592000
|
||||
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
|
||||
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
||||
|
|
|
@ -2770,7 +2770,7 @@ $collections = [
|
|||
'name' => 'Cache',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => 'dateAccessed',
|
||||
'$id' => 'accessedAt',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
|
@ -2797,7 +2797,7 @@ $collections = [
|
|||
[
|
||||
'$id' => '_key_accessed',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['dateAccessed'],
|
||||
'attributes' => ['accessedAt'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
],
|
||||
|
|
|
@ -53,16 +53,16 @@ $avatarCallback = function (string $type, string $code, int $width, int $height,
|
|||
if ($data) {
|
||||
//$output = (empty($output)) ? $type : $output;
|
||||
|
||||
$cacheRow = $dbForProject->getDocument('cache', $key);
|
||||
if($cacheRow->isEmpty()){
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
$fileCache = $dbForProject->getDocument('cache', $key);
|
||||
if ($fileCache->isEmpty()) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
'$id' => $key,
|
||||
'dateAccessed' => time(),
|
||||
'accessedAt' => time(),
|
||||
'path' => 'app-0'
|
||||
])));
|
||||
} else {
|
||||
$cacheRow->setAttribute('dateAccessed', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheRow->getId(), $cacheRow));
|
||||
$fileCache->setAttribute('accessedAt', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $fileCache->getId(), $fileCache));
|
||||
}
|
||||
|
||||
return $response
|
||||
|
@ -164,7 +164,7 @@ App::get('/v1/avatars/image')
|
|||
->param('height', 400, new Range(0, 2000), 'Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->action(function (string $url, int $width, int $height, Response $response, Database $dbForProject) {
|
||||
->action(function (string $url, int $width, int $height, Response $response, Database $dbForProject) {
|
||||
|
||||
$quality = 80;
|
||||
$output = 'png';
|
||||
|
@ -175,18 +175,18 @@ App::get('/v1/avatars/image')
|
|||
$data = $cache->load($key, 60 * 60 * 24 * 7/* 1 week */);
|
||||
|
||||
if ($data) {
|
||||
$cacheRow = $dbForProject->getDocument('cache', $key);
|
||||
$fileCache = $dbForProject->getDocument('cache', $key);
|
||||
|
||||
if($cacheRow->isEmpty()){
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
if ($fileCache->isEmpty()) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
'$id' => $key,
|
||||
'dateAccessed' => time(),
|
||||
'accessedAt' => time(),
|
||||
'path' => 'app-0'
|
||||
|
||||
])));
|
||||
} else {
|
||||
$cacheRow->setAttribute('dateAccessed', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheRow->getId(), $cacheRow));
|
||||
$fileCache->setAttribute('accessedAt', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $fileCache->getId(), $fileCache));
|
||||
}
|
||||
|
||||
return $response
|
||||
|
@ -255,17 +255,17 @@ App::get('/v1/avatars/favicon')
|
|||
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . '/app-0')); // Limit file number or size
|
||||
$data = $cache->load($key, 60 * 60 * 24 * 30 * 3/* 3 months */);
|
||||
if ($data) {
|
||||
$cacheRow = $dbForProject->getDocument('cache', $key);
|
||||
$fileCache = $dbForProject->getDocument('cache', $key);
|
||||
|
||||
if($cacheRow->isEmpty()){
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
if ($fileCache->isEmpty()) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
'$id' => $key,
|
||||
'dateAccessed' => time(),
|
||||
'accessedAt' => time(),
|
||||
'path' => 'app-0'
|
||||
])));
|
||||
} else {
|
||||
$cacheRow->setAttribute('dateAccessed', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheRow->getId(), $cacheRow));
|
||||
$fileCache->setAttribute('accessedAt', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $fileCache->getId(), $fileCache));
|
||||
}
|
||||
|
||||
return $response
|
||||
|
|
|
@ -913,17 +913,17 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
}
|
||||
|
||||
if ($data) {
|
||||
$cacheRow = $dbForProject->getDocument('cache', $key);
|
||||
$fileCache = $dbForProject->getDocument('cache', $key);
|
||||
|
||||
if($cacheRow->isEmpty()){
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
if ($fileCache->isEmpty()) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
|
||||
'$id' => $key,
|
||||
'dateAccessed' => time(),
|
||||
'accessedAt' => time(),
|
||||
'path' => 'app-' . $project->getId()
|
||||
])));
|
||||
} else {
|
||||
$cacheRow->setAttribute('dateAccessed', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheRow->getId(), $cacheRow));
|
||||
$fileCache->setAttribute('accessedAt', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $fileCache->getId(), $fileCache));
|
||||
}
|
||||
|
||||
return $response
|
||||
|
|
|
@ -132,24 +132,28 @@ class DeletesV1 extends Worker
|
|||
/**
|
||||
* @param int $timestamp
|
||||
*/
|
||||
protected function deleteCache( int $timestamp): void
|
||||
protected function deleteCache(int $timestamp): void
|
||||
{
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
$cache = new Local(APP_STORAGE_CACHE);
|
||||
|
||||
$this->deleteByGroup('cache', [
|
||||
new Query('dateAccessed', Query::TYPE_LESSER, [$timestamp])
|
||||
], $dbForProject
|
||||
, function (Document $document) use ($cache) {
|
||||
$this->deleteByGroup(
|
||||
'cache',
|
||||
[
|
||||
new Query('accessedAt', Query::TYPE_LESSER, [$timestamp])
|
||||
],
|
||||
$dbForProject,
|
||||
function (Document $document) use ($cache) {
|
||||
$path = $cache->getRoot() . '/' . $document->getAttribute('path') . '/' . $document->getId();
|
||||
if ($cache->delete($path)) {
|
||||
Console::success('Deleting cache file: ' . $path);
|
||||
} else {
|
||||
Console::error('**Failed to delete cache file: ' . $path);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -311,16 +315,14 @@ class DeletesV1 extends Worker
|
|||
protected function deleteExpiredSessions(int $timestamp): void
|
||||
{
|
||||
$this->deleteForProjectIds(
|
||||
|
||||
function (string $projectId) use ($timestamp) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
// Delete Sessions
|
||||
$this->deleteByGroup('sessions', [
|
||||
$this->deleteByGroup('sessions', [
|
||||
new Query('expire', Query::TYPE_LESSER, [$timestamp])
|
||||
], $dbForProject);
|
||||
|
||||
|
||||
});
|
||||
], $dbForProject);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue