1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

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
This commit is contained in:
epriestley 2017-06-22 10:52:40 -07:00
parent bd3f441098
commit 224c4692ee
4 changed files with 46 additions and 0 deletions

View file

@ -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',

View file

@ -64,7 +64,11 @@ final class PhabricatorCacheManagementPurgeWorkflow
}
}
$viewer = $this->getViewer();
foreach ($purgers as $key => $purger) {
$purger->setViewer($viewer);
echo tsprintf(
"%s\n",
pht(

View file

@ -0,0 +1,22 @@
<?php
final class PhabricatorBuiltinFileCachePurger
extends PhabricatorCachePurger {
const PURGERKEY = 'builtin-file';
public function purgeCache() {
$viewer = $this->getViewer();
$files = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withIsBuiltin(true)
->execute();
$engine = new PhabricatorDestructionEngine();
foreach ($files as $file) {
$engine->destroyObject($file);
}
}
}

View file

@ -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;
}