diff --git a/Dockerfile b/Dockerfile index 37a65d6054..bf3f4f1634 100755 --- a/Dockerfile +++ b/Dockerfile @@ -118,6 +118,7 @@ RUN mkdir -p /storage/uploads && \ # Executables RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/patch-delete-schedule-updated-at-attribute && \ + chmod +x /usr/local/bin/clear-card-cache && \ chmod +x /usr/local/bin/maintenance && \ chmod +x /usr/local/bin/volume-sync && \ chmod +x /usr/local/bin/usage && \ diff --git a/bin/clear-card-cache b/bin/clear-card-cache new file mode 100644 index 0000000000..b39bc13651 --- /dev/null +++ b/bin/clear-card-cache @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php clear-card-cache $@ \ No newline at end of file diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index a0c5d3a547..b82dca422f 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -14,6 +14,7 @@ use Appwrite\Platform\Tasks\Specs; use Appwrite\Platform\Tasks\SSL; use Appwrite\Platform\Tasks\Hamster; use Appwrite\Platform\Tasks\PatchDeleteScheduleUpdatedAtAttribute; +use Appwrite\Platform\Tasks\ClearCardCache; use Appwrite\Platform\Tasks\Usage; use Appwrite\Platform\Tasks\Vars; use Appwrite\Platform\Tasks\Version; @@ -34,6 +35,7 @@ class Tasks extends Service ->addAction(Install::getName(), new Install()) ->addAction(Maintenance::getName(), new Maintenance()) ->addAction(PatchCreateMissingSchedules::getName(), new PatchCreateMissingSchedules()) + ->addAction(ClearCardCache::getName(), new ClearCardCache()) ->addAction(PatchDeleteScheduleUpdatedAtAttribute::getName(), new PatchDeleteScheduleUpdatedAtAttribute()) ->addAction(Schedule::getName(), new Schedule()) ->addAction(Migrate::getName(), new Migrate()) diff --git a/src/Appwrite/Platform/Tasks/ClearCardCache.php b/src/Appwrite/Platform/Tasks/ClearCardCache.php new file mode 100644 index 0000000000..d3153b995c --- /dev/null +++ b/src/Appwrite/Platform/Tasks/ClearCardCache.php @@ -0,0 +1,62 @@ +desc('Deletes card cache for specific user') + ->param('userId', '', new UID(), 'User UID.', false) + ->inject('dbForConsole') + ->callback(fn (string $userId, Database $dbForConsole) => $this->action($userId, $dbForConsole)); + } + + public function action(string $userId, Database $dbForConsole): void + { + Authorization::disable(); + Authorization::setDefaultStatus(false); + + Console::title('ClearCardCache V1'); + Console::success(APP_NAME . ' ClearCardCache v1 has started'); + $resources = ['card/' . $userId, 'card-back/' . $userId, 'card-og/' . $userId]; + + $caches = Authorization::skip(fn () => $dbForConsole->find('cache', [ + Query::equal('resource', $resources), + Query::limit(100) + ])); + + $count = \count($caches); + Console::info("Going to delete {$count} cache records in 10 seconds..."); + \sleep(10); + + foreach ($caches as $cache) { + $key = $cache->getId(); + + $cacheFolder = new Cache( + new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-console') + ); + + $cacheFolder->purge($key); + + Authorization::skip(fn () => $dbForConsole->deleteDocument('cache', $cache->getId())); + } + + Console::success(APP_NAME . ' ClearCardCache v1 has finished'); + } +}