From b7aab21698e2238d4a914975c0f6cae0a3ec01e0 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 13 Jul 2023 13:36:14 +0300 Subject: [PATCH] cache deleteById to deleteByGroup --- app/workers/deletes.php | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 39bd1c9954..f3876ba9c8 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -136,30 +136,31 @@ class DeletesV1 extends Worker */ protected function deleteCacheByResource(Document $project, string $resource): void { - $projectId = $project->getId(); - $dbForProject = $this->getProjectDB($projectId); - $document = $dbForProject->findOne('cache', [Query::equal('resource', [$resource])]); + $dbForProject = $this->getProjectDB($project); - if ($document) { - $cache = new Cache( - new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $projectId) - ); + $cache = new Cache( + 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(); + $query = [ + Query::equal('resource', [$resource]) + ]; - if ($cache->purge($document->getId())) { - Console::success('Deleting cache file: ' . $path); - } else { - Console::error('Failed to delete cache file: ' . $path); - } + $this->deleteByGroup( + 'cache', + $query, + $dbForProject, + function (Document $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); } - ); - } + } + ); } /**