From 224c4692ee0e1d11950c18b55d43d82feeed1905 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 Jun 2017 10:52:40 -0700 Subject: [PATCH] Add a cache purger for builtin files Summary: Fixes T12859. Test Plan: - Loaded Diffusion builtin icons before recent updates, saw cached builtins. - Ran `bin/cache purge --caches builtin-file`. - Reloaded, saw new files. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12859 Differential Revision: https://secure.phabricator.com/D18147 --- src/__phutil_library_map__.php | 2 ++ ...habricatorCacheManagementPurgeWorkflow.php | 4 ++++ .../PhabricatorBuiltinFileCachePurger.php | 22 +++++++++++++++++++ .../files/query/PhabricatorFileQuery.php | 18 +++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 src/applications/cache/purger/PhabricatorBuiltinFileCachePurger.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d7b197028f..0384c4b5f8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2162,6 +2162,7 @@ phutil_register_library_map(array( 'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php', 'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php', 'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php', + 'PhabricatorBuiltinFileCachePurger' => 'applications/cache/purger/PhabricatorBuiltinFileCachePurger.php', 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', 'PhabricatorBulkContentSource' => 'infrastructure/daemon/contentsource/PhabricatorBulkContentSource.php', 'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php', @@ -7362,6 +7363,7 @@ phutil_register_library_map(array( 'PhabricatorBoolEditField' => 'PhabricatorEditField', 'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation', 'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine', + 'PhabricatorBuiltinFileCachePurger' => 'PhabricatorCachePurger', 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 'PhabricatorBulkContentSource' => 'PhabricatorContentSource', 'PhabricatorCacheDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php b/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php index d40c0f35e6..cfe42c918b 100644 --- a/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php +++ b/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php @@ -64,7 +64,11 @@ final class PhabricatorCacheManagementPurgeWorkflow } } + $viewer = $this->getViewer(); + foreach ($purgers as $key => $purger) { + $purger->setViewer($viewer); + echo tsprintf( "%s\n", pht( diff --git a/src/applications/cache/purger/PhabricatorBuiltinFileCachePurger.php b/src/applications/cache/purger/PhabricatorBuiltinFileCachePurger.php new file mode 100644 index 0000000000..a4bc682c02 --- /dev/null +++ b/src/applications/cache/purger/PhabricatorBuiltinFileCachePurger.php @@ -0,0 +1,22 @@ +getViewer(); + + $files = id(new PhabricatorFileQuery()) + ->setViewer($viewer) + ->withIsBuiltin(true) + ->execute(); + + $engine = new PhabricatorDestructionEngine(); + foreach ($files as $file) { + $engine->destroyObject($file); + } + } + +} diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php index a2de5ca6ab..071ee03991 100644 --- a/src/applications/files/query/PhabricatorFileQuery.php +++ b/src/applications/files/query/PhabricatorFileQuery.php @@ -18,6 +18,7 @@ final class PhabricatorFileQuery private $isDeleted; private $needTransforms; private $builtinKeys; + private $isBuiltin; public function withIDs(array $ids) { $this->ids = $ids; @@ -54,6 +55,11 @@ final class PhabricatorFileQuery return $this; } + public function withIsBuiltin($is_builtin) { + $this->isBuiltin = $is_builtin; + return $this; + } + /** * Select files which are transformations of some other file. For example, * you can use this query to find previously generated thumbnails of an image @@ -416,6 +422,18 @@ final class PhabricatorFileQuery $this->builtinKeys); } + if ($this->isBuiltin !== null) { + if ($this->isBuiltin) { + $where[] = qsprintf( + $conn, + 'builtinKey IS NOT NULL'); + } else { + $where[] = qsprintf( + $conn, + 'builtinKey IS NULL'); + } + } + return $where; }