1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-21 22:32:41 +01:00

Provide 'bin/cache', for managing caches

Summary:
See <https://github.com/facebook/phabricator/issues/323>. We have a very old cache management script which doesn't purge all the modern caches (and does purge some caches which are no longer in use). Update it so it purges all the modern caches (remarkup, general, changeset), no longer purges outdated caches, and is easier to use.

Also delete a lot of "this script has moved" scripts from the last few rounds of similar cleanup, I believe all of these have been in master for at least several months, which should be enough time for users to get used to the new stuff.

Test Plan: Ran `bin/cache` with various arguments. Verified caches were purged.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5978
This commit is contained in:
epriestley 2013-05-20 10:16:35 -07:00
parent 3990b38b5b
commit e01ceaa07f
14 changed files with 138 additions and 180 deletions

1
bin/cache Symbolic link
View file

@ -0,0 +1 @@
../scripts/cache/manage_cache.php

22
scripts/cache/manage_cache.php vendored Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('manage mail');
$args->setSynopsis(<<<EOSYNOPSIS
**cache** __command__ [__options__]
Manage Phabricator caches.
EOSYNOPSIS
);
$args->parseStandardArguments();
$workflows = array(
new PhabricatorCacheManagementPurgeWorkflow(),
new PhutilHelpArgumentWorkflow(),
);
$args->parseWorkflows($workflows);

View file

@ -1,8 +0,0 @@
#!/usr/bin/env php
<?php
echo
"This script has moved. All repository management is now performed through ".
"'bin/repository'. Use this command instead:\n\n".
" phabricator/ $ ./bin/repository discover ...\n";
exit(1);

View file

@ -1,7 +0,0 @@
#!/usr/bin/env php
<?php
echo "This script is obsolete. Instead, use:\n\n".
" $ reparse.php <commit_name> --message --change\n\n".
"See that script for more options.\n";
exit(1);

View file

@ -1,8 +0,0 @@
#!/usr/bin/env php
<?php
echo
"This script has moved. All repository management is now performed through ".
"'bin/repository'. Use this command instead:\n\n".
" phabricator/ $ ./bin/repository pull ...\n";
exit(1);

View file

@ -1,8 +0,0 @@
#!/usr/bin/env php
<?php
echo "This script is obsolete. Instead, use:\n\n".
" $ reparse.php --all <repository_name> --message\n\n".
"See that script for more options.\n";
exit(1);

View file

@ -1,5 +0,0 @@
#!/usr/bin/env php
<?php
echo "Use 'bin/search index rXnnnnnn' instead of this script.\n";
exit(1);

View file

@ -1,5 +0,0 @@
#!/usr/bin/env php
<?php
echo "Use 'bin/search index --type USER' instead of this script.\n";
die(1);

View file

@ -1,5 +0,0 @@
#!/usr/bin/env php
<?php
echo "Use 'bin/search index --all' instead of this script.\n";
die(1);

View file

@ -1,10 +0,0 @@
#!/usr/bin/env php
<?php
echo "This script has been replaced by 'phabricator/bin/storage'.\n\n".
"Run:\n\n".
" phabricator/bin $ ./storage help\n\n".
"...for help, or:\n\n".
" phabricator/bin $ ./storage upgrade\n\n".
"...to upgrade storage.\n\n";
exit(1);

View file

@ -1,127 +1,5 @@
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$purge_changesets = false;
$purge_differential = false;
$args = array_slice($argv, 1);
if (!$args) {
usage("Specify which caches you want to purge.");
}
$changesets = array();
$len = count($args);
for ($ii = 0; $ii < $len; $ii++) {
switch ($args[$ii]) {
case '--all':
$purge_changesets = true;
$purge_differential = true;
break;
case '--changesets':
$purge_changesets = true;
while (isset($args[$ii + 1]) && (substr($args[$ii + 1], 0, 2) !== '--')) {
$changeset = $args[++$ii];
if (!is_numeric($changeset)) {
return usage("Changeset argument '{$changeset}' ".
"is not a positive integer.");
}
$changesets[] = intval($changeset);
}
break;
case '--differential':
$purge_differential = true;
break;
case '--help':
return help();
default:
return usage("Unrecognized argument '{$args[$ii]}'.");
}
}
if ($purge_changesets) {
$table = new DifferentialChangeset();
if ($changesets) {
echo "Purging changeset cache for changesets ".
implode($changesets, ",")."\n";
queryfx(
$table->establishConnection('w'),
'DELETE FROM %T WHERE id IN (%Ld)',
DifferentialChangeset::TABLE_CACHE,
$changesets);
} else {
echo "Purging changeset cache...\n";
queryfx(
$table->establishConnection('w'),
'TRUNCATE TABLE %T',
DifferentialChangeset::TABLE_CACHE);
}
echo "Done.\n";
}
if ($purge_differential) {
echo "Purging Differential comment cache...\n";
$table = new DifferentialComment();
queryfx(
$table->establishConnection('w'),
'UPDATE %T SET cache = NULL',
$table->getTableName());
echo "Purging Differential inline comment cache...\n";
$table = new DifferentialInlineComment();
queryfx(
$table->establishConnection('w'),
'UPDATE %T SET cache = NULL',
$table->getTableName());
echo "Done.\n";
}
echo "Ok, caches purged.\n";
function usage($message) {
echo "Usage Error: {$message}";
echo "\n\n";
echo "Run 'purge_cache.php --help' for detailed help.\n";
exit(1);
}
function help() {
$help = <<<EOHELP
**SUMMARY**
**purge_cache.php**
[--differential]
[--changesets [changeset_id ...]]
**purge_cache.php** --all
**purge_cache.php** --help
Purge various long-lived caches. Normally, Phabricator caches some data for
a long time or indefinitely, but certain configuration changes might
invalidate these caches. You can use this script to manually purge them.
For instance, if you change display widths in Differential or configure
syntax highlighting, you may want to purge the changeset cache (with
"--changesets") so your changes are reflected in older diffs.
If you change Remarkup rules, you may want to purge the Differential
comment caches ("--differential") so older comments pick up the new rules.
__--all__
Purge all long-lived caches.
__--changesets [changeset_id ...]__
Purge Differential changeset render cache. If changeset_ids are present,
the script will delete the cache for those changesets; otherwise it will
delete the cache for all the changesets.
__--differential__
Purge Differential comment formatting cache.
__--help__: show this help
EOHELP;
echo phutil_console_format($help);
exit(1);
}
echo "This script is obsolete. Use 'bin/cache' instead.\n";
exit(1);

View file

@ -807,6 +807,8 @@ phutil_register_library_map(array(
'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php',
'PhabricatorButtonsExample' => 'applications/uiexample/examples/PhabricatorButtonsExample.php',
'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php',
'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php',
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/PhabricatorCalendarBrowseController.php',
'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php',
@ -2575,6 +2577,8 @@ phutil_register_library_map(array(
'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList',
'PhabricatorButtonsExample' => 'PhabricatorUIExample',
'PhabricatorCacheDAO' => 'PhabricatorLiskDAO',
'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorCacheManagementWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
'PhabricatorCalendarController' => 'PhabricatorController',
'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO',

View file

@ -0,0 +1,99 @@
<?php
final class PhabricatorCacheManagementPurgeWorkflow
extends PhabricatorSearchManagementWorkflow {
protected function didConstruct() {
$this
->setName('purge')
->setSynopsis('Drop data from caches.')
->setArguments(
array(
array(
'name' => 'purge-all',
'help' => 'Purge all caches.',
),
array(
'name' => 'purge-remarkup',
'help' => 'Purge the remarkup cache.',
),
array(
'name' => 'purge-changeset',
'help' => 'Purge the Differential changeset cache.',
),
array(
'name' => 'purge-general',
'help' => 'Purge the general cache.',
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$purge_all = $args->getArg('purge-all');
$purge = array(
'remarkup' => $purge_all || $args->getArg('purge-remarkup'),
'changeset' => $purge_all || $args->getArg('purge-changeset'),
'general' => $purge_all || $args->getArg('purge-general'),
);
if (!array_filter($purge)) {
$list = array();
foreach ($purge as $key => $ignored) {
$list[] = "'--purge-".$key."'";
}
throw new PhutilArgumentUsageException(
"Specify which cache or caches to purge, or use '--purge-all'. ".
"Available caches are: ".implode(', ', $list).". Use '--help' ".
"for more information.");
}
if ($purge['remarkup']) {
$console->writeOut("Purging remarkup cache...");
$this->purgeRemarkupCache();
$console->writeOut("done.\n");
}
if ($purge['changeset']) {
$console->writeOut("Purging changeset cache...");
$this->purgeChangesetCache();
$console->writeOut("done.\n");
}
if ($purge['general']) {
$console->writeOut("Purging general cache...");
$this->purgeGeneralCache();
$console->writeOut("done.\n");
}
}
private function purgeRemarkupCache() {
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
id(new PhabricatorMarkupCache())->getTableName());
}
private function purgeChangesetCache() {
$conn_w = id(new DifferentialChangeset())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
DifferentialChangeset::TABLE_CACHE);
}
private function purgeGeneralCache() {
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
'cache_general');
}
}

View file

@ -0,0 +1,10 @@
<?php
abstract class PhabricatorCacheManagementWorkflow
extends PhutilArgumentWorkflow {
final public function isExecutable() {
return true;
}
}