cache deletion bug fix
This commit is contained in:
parent
fd7a2cbfad
commit
13066c3dde
2 changed files with 49 additions and 25 deletions
|
@ -654,11 +654,6 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
->setContext('bucket', $bucket)
|
->setContext('bucket', $bucket)
|
||||||
;
|
;
|
||||||
|
|
||||||
$deletes
|
|
||||||
->setType(DELETE_TYPE_CACHE_BY_RESOURCE)
|
|
||||||
->setResource('file/' . $file->getId())
|
|
||||||
;
|
|
||||||
|
|
||||||
$metadata = null; // was causing leaks as it was passed by reference
|
$metadata = null; // was causing leaks as it was passed by reference
|
||||||
|
|
||||||
$response
|
$response
|
||||||
|
@ -1341,6 +1336,11 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
$file = Authorization::skip(fn() => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file));
|
$file = Authorization::skip(fn() => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$deletes
|
||||||
|
->setType(DELETE_TYPE_CACHE_BY_RESOURCE)
|
||||||
|
->setResource('file/' . $file->getId())
|
||||||
|
;
|
||||||
|
|
||||||
$events
|
$events
|
||||||
->setParam('bucketId', $bucket->getId())
|
->setParam('bucketId', $bucket->getId())
|
||||||
->setParam('fileId', $file->getId())
|
->setParam('fileId', $file->getId())
|
||||||
|
|
|
@ -114,10 +114,10 @@ class DeletesV1 extends Worker
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETE_TYPE_CACHE_BY_RESOURCE:
|
case DELETE_TYPE_CACHE_BY_RESOURCE:
|
||||||
$this->deleteCacheByResource($project->getId());
|
$this->deleteCacheByResource($project, $this->args['resource']);
|
||||||
break;
|
break;
|
||||||
case DELETE_TYPE_CACHE_BY_TIMESTAMP:
|
case DELETE_TYPE_CACHE_BY_TIMESTAMP:
|
||||||
$this->deleteCacheByDate();
|
$this->deleteCacheByDate($this->args['datetime']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console::error('No delete operation for type: ' . $type);
|
Console::error('No delete operation for type: ' . $type);
|
||||||
|
@ -130,31 +130,55 @@ class DeletesV1 extends Worker
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $projectId
|
* @param Document $project
|
||||||
|
* @param string $resource
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function deleteCacheByResource(string $projectId): void
|
protected function deleteCacheByResource(Document $project, string $resource): void
|
||||||
{
|
{
|
||||||
$this->deleteCacheFiles([
|
$dbForProject = $this->getProjectDB($project);
|
||||||
Query::equal('resource', [$this->args['resource']]),
|
$projectId = $project->getId();
|
||||||
]);
|
$document = $dbForProject->findOne('cache', [Query::equal('resource', [$resource])]);
|
||||||
}
|
|
||||||
|
|
||||||
protected function deleteCacheByDate(): void
|
if ($document) {
|
||||||
{
|
|
||||||
$this->deleteCacheFiles([
|
|
||||||
Query::lessThan('accessedAt', $this->args['datetime']),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function deleteCacheFiles($query): void
|
|
||||||
{
|
|
||||||
$this->deleteForProjectIds(function (string $projectId) use ($query) {
|
|
||||||
|
|
||||||
$dbForProject = $this->getProjectDB($projectId);
|
|
||||||
$cache = new Cache(
|
$cache = new Cache(
|
||||||
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $projectId)
|
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $projectId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->deleteById(
|
||||||
|
$document,
|
||||||
|
$dbForProject,
|
||||||
|
function ($document) use ($cache, $projectId) {
|
||||||
|
$path = APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $projectId . DIRECTORY_SEPARATOR . $document->getId();
|
||||||
|
|
||||||
|
if ($cache->purge($document->getId())) {
|
||||||
|
Console::success('Deleting cache file: ' . $path);
|
||||||
|
} else {
|
||||||
|
Console::error('Failed to delete cache file: ' . $path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $datetime
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected function deleteCacheByDate(string $datetime): void
|
||||||
|
{
|
||||||
|
$this->deleteForProjectIds(function (Document $project) use ($datetime) {
|
||||||
|
|
||||||
|
$projectId = $project->getId();
|
||||||
|
$dbForProject = $this->getProjectDB($project);
|
||||||
|
$cache = new Cache(
|
||||||
|
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $projectId)
|
||||||
|
);
|
||||||
|
|
||||||
|
$query = [
|
||||||
|
Query::lessThan('accessedAt', $datetime),
|
||||||
|
];
|
||||||
|
|
||||||
$this->deleteByGroup(
|
$this->deleteByGroup(
|
||||||
'cache',
|
'cache',
|
||||||
$query,
|
$query,
|
||||||
|
|
Loading…
Reference in a new issue