Merge pull request #5465 from appwrite/fix-cloud-cards-cache
Feat: Card cache busting
This commit is contained in:
commit
76f2e0eeac
4 changed files with 68 additions and 0 deletions
|
@ -118,6 +118,7 @@ RUN mkdir -p /storage/uploads && \
|
||||||
# Executables
|
# Executables
|
||||||
RUN chmod +x /usr/local/bin/doctor && \
|
RUN chmod +x /usr/local/bin/doctor && \
|
||||||
chmod +x /usr/local/bin/patch-delete-schedule-updated-at-attribute && \
|
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/maintenance && \
|
||||||
chmod +x /usr/local/bin/volume-sync && \
|
chmod +x /usr/local/bin/volume-sync && \
|
||||||
chmod +x /usr/local/bin/usage && \
|
chmod +x /usr/local/bin/usage && \
|
||||||
|
|
3
bin/clear-card-cache
Normal file
3
bin/clear-card-cache
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
php /usr/src/code/app/cli.php clear-card-cache $@
|
|
@ -14,6 +14,7 @@ use Appwrite\Platform\Tasks\Specs;
|
||||||
use Appwrite\Platform\Tasks\SSL;
|
use Appwrite\Platform\Tasks\SSL;
|
||||||
use Appwrite\Platform\Tasks\Hamster;
|
use Appwrite\Platform\Tasks\Hamster;
|
||||||
use Appwrite\Platform\Tasks\PatchDeleteScheduleUpdatedAtAttribute;
|
use Appwrite\Platform\Tasks\PatchDeleteScheduleUpdatedAtAttribute;
|
||||||
|
use Appwrite\Platform\Tasks\ClearCardCache;
|
||||||
use Appwrite\Platform\Tasks\Usage;
|
use Appwrite\Platform\Tasks\Usage;
|
||||||
use Appwrite\Platform\Tasks\Vars;
|
use Appwrite\Platform\Tasks\Vars;
|
||||||
use Appwrite\Platform\Tasks\Version;
|
use Appwrite\Platform\Tasks\Version;
|
||||||
|
@ -34,6 +35,7 @@ class Tasks extends Service
|
||||||
->addAction(Install::getName(), new Install())
|
->addAction(Install::getName(), new Install())
|
||||||
->addAction(Maintenance::getName(), new Maintenance())
|
->addAction(Maintenance::getName(), new Maintenance())
|
||||||
->addAction(PatchCreateMissingSchedules::getName(), new PatchCreateMissingSchedules())
|
->addAction(PatchCreateMissingSchedules::getName(), new PatchCreateMissingSchedules())
|
||||||
|
->addAction(ClearCardCache::getName(), new ClearCardCache())
|
||||||
->addAction(PatchDeleteScheduleUpdatedAtAttribute::getName(), new PatchDeleteScheduleUpdatedAtAttribute())
|
->addAction(PatchDeleteScheduleUpdatedAtAttribute::getName(), new PatchDeleteScheduleUpdatedAtAttribute())
|
||||||
->addAction(Schedule::getName(), new Schedule())
|
->addAction(Schedule::getName(), new Schedule())
|
||||||
->addAction(Migrate::getName(), new Migrate())
|
->addAction(Migrate::getName(), new Migrate())
|
||||||
|
|
62
src/Appwrite/Platform/Tasks/ClearCardCache.php
Normal file
62
src/Appwrite/Platform/Tasks/ClearCardCache.php
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Platform\Tasks;
|
||||||
|
|
||||||
|
use Utopia\Cache\Adapter\Filesystem;
|
||||||
|
use Utopia\Cache\Cache;
|
||||||
|
use Utopia\Platform\Action;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\Database\Database;
|
||||||
|
use Utopia\Database\Validator\Authorization;
|
||||||
|
use Utopia\Database\Validator\UID;
|
||||||
|
|
||||||
|
class ClearCardCache extends Action
|
||||||
|
{
|
||||||
|
public static function getName(): string
|
||||||
|
{
|
||||||
|
return 'clear-card-cache';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->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');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue