Skip to content

Commit e01ceaa

Browse files
author
epriestley
committed
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
1 parent 3990b38 commit e01ceaa

14 files changed

+138
-180
lines changed

bin/cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/cache/manage_cache.php

scripts/cache/manage_cache.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$root = dirname(dirname(dirname(__FILE__)));
5+
require_once $root.'/scripts/__init_script__.php';
6+
7+
$args = new PhutilArgumentParser($argv);
8+
$args->setTagline('manage mail');
9+
$args->setSynopsis(<<<EOSYNOPSIS
10+
**cache** __command__ [__options__]
11+
Manage Phabricator caches.
12+
13+
EOSYNOPSIS
14+
);
15+
$args->parseStandardArguments();
16+
17+
$workflows = array(
18+
new PhabricatorCacheManagementPurgeWorkflow(),
19+
new PhutilHelpArgumentWorkflow(),
20+
);
21+
22+
$args->parseWorkflows($workflows);

scripts/repository/discover.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/repository/parse_one_commit.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

scripts/repository/pull.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/repository/reparse_all_commit_messages.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/search/index_one_commit.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/search/reindex_all_users.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/search/reindex_everything.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/sql/upgrade_schema.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

scripts/util/purge_cache.php

Lines changed: 2 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,5 @@
11
#!/usr/bin/env php
22
<?php
33

4-
$root = dirname(dirname(dirname(__FILE__)));
5-
require_once $root.'/scripts/__init_script__.php';
6-
7-
$purge_changesets = false;
8-
$purge_differential = false;
9-
10-
$args = array_slice($argv, 1);
11-
if (!$args) {
12-
usage("Specify which caches you want to purge.");
13-
}
14-
15-
$changesets = array();
16-
$len = count($args);
17-
for ($ii = 0; $ii < $len; $ii++) {
18-
switch ($args[$ii]) {
19-
case '--all':
20-
$purge_changesets = true;
21-
$purge_differential = true;
22-
break;
23-
case '--changesets':
24-
$purge_changesets = true;
25-
while (isset($args[$ii + 1]) && (substr($args[$ii + 1], 0, 2) !== '--')) {
26-
$changeset = $args[++$ii];
27-
if (!is_numeric($changeset)) {
28-
return usage("Changeset argument '{$changeset}' ".
29-
"is not a positive integer.");
30-
}
31-
$changesets[] = intval($changeset);
32-
}
33-
break;
34-
case '--differential':
35-
$purge_differential = true;
36-
break;
37-
case '--help':
38-
return help();
39-
default:
40-
return usage("Unrecognized argument '{$args[$ii]}'.");
41-
}
42-
}
43-
44-
if ($purge_changesets) {
45-
$table = new DifferentialChangeset();
46-
if ($changesets) {
47-
echo "Purging changeset cache for changesets ".
48-
implode($changesets, ",")."\n";
49-
queryfx(
50-
$table->establishConnection('w'),
51-
'DELETE FROM %T WHERE id IN (%Ld)',
52-
DifferentialChangeset::TABLE_CACHE,
53-
$changesets);
54-
} else {
55-
echo "Purging changeset cache...\n";
56-
queryfx(
57-
$table->establishConnection('w'),
58-
'TRUNCATE TABLE %T',
59-
DifferentialChangeset::TABLE_CACHE);
60-
}
61-
echo "Done.\n";
62-
}
63-
64-
if ($purge_differential) {
65-
echo "Purging Differential comment cache...\n";
66-
$table = new DifferentialComment();
67-
queryfx(
68-
$table->establishConnection('w'),
69-
'UPDATE %T SET cache = NULL',
70-
$table->getTableName());
71-
echo "Purging Differential inline comment cache...\n";
72-
$table = new DifferentialInlineComment();
73-
queryfx(
74-
$table->establishConnection('w'),
75-
'UPDATE %T SET cache = NULL',
76-
$table->getTableName());
77-
echo "Done.\n";
78-
}
79-
80-
echo "Ok, caches purged.\n";
81-
82-
function usage($message) {
83-
echo "Usage Error: {$message}";
84-
echo "\n\n";
85-
echo "Run 'purge_cache.php --help' for detailed help.\n";
86-
exit(1);
87-
}
88-
89-
function help() {
90-
$help = <<<EOHELP
91-
**SUMMARY**
92-
93-
**purge_cache.php**
94-
[--differential]
95-
[--changesets [changeset_id ...]]
96-
**purge_cache.php** --all
97-
**purge_cache.php** --help
98-
99-
Purge various long-lived caches. Normally, Phabricator caches some data for
100-
a long time or indefinitely, but certain configuration changes might
101-
invalidate these caches. You can use this script to manually purge them.
102-
103-
For instance, if you change display widths in Differential or configure
104-
syntax highlighting, you may want to purge the changeset cache (with
105-
"--changesets") so your changes are reflected in older diffs.
106-
107-
If you change Remarkup rules, you may want to purge the Differential
108-
comment caches ("--differential") so older comments pick up the new rules.
109-
110-
__--all__
111-
Purge all long-lived caches.
112-
113-
__--changesets [changeset_id ...]__
114-
Purge Differential changeset render cache. If changeset_ids are present,
115-
the script will delete the cache for those changesets; otherwise it will
116-
delete the cache for all the changesets.
117-
118-
__--differential__
119-
Purge Differential comment formatting cache.
120-
121-
__--help__: show this help
122-
123-
124-
EOHELP;
125-
echo phutil_console_format($help);
126-
exit(1);
127-
}
4+
echo "This script is obsolete. Use 'bin/cache' instead.\n";
5+
exit(1);

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@
807807
'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php',
808808
'PhabricatorButtonsExample' => 'applications/uiexample/examples/PhabricatorButtonsExample.php',
809809
'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php',
810+
'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php',
811+
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
810812
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
811813
'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/PhabricatorCalendarBrowseController.php',
812814
'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php',
@@ -2575,6 +2577,8 @@
25752577
'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList',
25762578
'PhabricatorButtonsExample' => 'PhabricatorUIExample',
25772579
'PhabricatorCacheDAO' => 'PhabricatorLiskDAO',
2580+
'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorSearchManagementWorkflow',
2581+
'PhabricatorCacheManagementWorkflow' => 'PhutilArgumentWorkflow',
25782582
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
25792583
'PhabricatorCalendarController' => 'PhabricatorController',
25802584
'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO',
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
final class PhabricatorCacheManagementPurgeWorkflow
4+
extends PhabricatorSearchManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$this
8+
->setName('purge')
9+
->setSynopsis('Drop data from caches.')
10+
->setArguments(
11+
array(
12+
array(
13+
'name' => 'purge-all',
14+
'help' => 'Purge all caches.',
15+
),
16+
array(
17+
'name' => 'purge-remarkup',
18+
'help' => 'Purge the remarkup cache.',
19+
),
20+
array(
21+
'name' => 'purge-changeset',
22+
'help' => 'Purge the Differential changeset cache.',
23+
),
24+
array(
25+
'name' => 'purge-general',
26+
'help' => 'Purge the general cache.',
27+
),
28+
));
29+
}
30+
31+
public function execute(PhutilArgumentParser $args) {
32+
$console = PhutilConsole::getConsole();
33+
34+
$purge_all = $args->getArg('purge-all');
35+
36+
$purge = array(
37+
'remarkup' => $purge_all || $args->getArg('purge-remarkup'),
38+
'changeset' => $purge_all || $args->getArg('purge-changeset'),
39+
'general' => $purge_all || $args->getArg('purge-general'),
40+
);
41+
42+
if (!array_filter($purge)) {
43+
$list = array();
44+
foreach ($purge as $key => $ignored) {
45+
$list[] = "'--purge-".$key."'";
46+
}
47+
48+
throw new PhutilArgumentUsageException(
49+
"Specify which cache or caches to purge, or use '--purge-all'. ".
50+
"Available caches are: ".implode(', ', $list).". Use '--help' ".
51+
"for more information.");
52+
}
53+
54+
if ($purge['remarkup']) {
55+
$console->writeOut("Purging remarkup cache...");
56+
$this->purgeRemarkupCache();
57+
$console->writeOut("done.\n");
58+
}
59+
60+
if ($purge['changeset']) {
61+
$console->writeOut("Purging changeset cache...");
62+
$this->purgeChangesetCache();
63+
$console->writeOut("done.\n");
64+
}
65+
66+
if ($purge['general']) {
67+
$console->writeOut("Purging general cache...");
68+
$this->purgeGeneralCache();
69+
$console->writeOut("done.\n");
70+
}
71+
}
72+
73+
private function purgeRemarkupCache() {
74+
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
75+
76+
queryfx(
77+
$conn_w,
78+
'TRUNCATE TABLE %T',
79+
id(new PhabricatorMarkupCache())->getTableName());
80+
}
81+
82+
private function purgeChangesetCache() {
83+
$conn_w = id(new DifferentialChangeset())->establishConnection('w');
84+
queryfx(
85+
$conn_w,
86+
'TRUNCATE TABLE %T',
87+
DifferentialChangeset::TABLE_CACHE);
88+
}
89+
90+
private function purgeGeneralCache() {
91+
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
92+
93+
queryfx(
94+
$conn_w,
95+
'TRUNCATE TABLE %T',
96+
'cache_general');
97+
}
98+
99+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
abstract class PhabricatorCacheManagementWorkflow
4+
extends PhutilArgumentWorkflow {
5+
6+
final public function isExecutable() {
7+
return true;
8+
}
9+
10+
}

0 commit comments

Comments
 (0)