@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+138 -180
+1
bin/cache
··· 1 + ../scripts/cache/manage_cache.php
+22
scripts/cache/manage_cache.php
··· 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);
-8
scripts/repository/discover.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo 5 - "This script has moved. All repository management is now performed through ". 6 - "'bin/repository'. Use this command instead:\n\n". 7 - " phabricator/ $ ./bin/repository discover ...\n"; 8 - exit(1);
-7
scripts/repository/parse_one_commit.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "This script is obsolete. Instead, use:\n\n". 5 - " $ reparse.php <commit_name> --message --change\n\n". 6 - "See that script for more options.\n"; 7 - exit(1);
-8
scripts/repository/pull.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo 5 - "This script has moved. All repository management is now performed through ". 6 - "'bin/repository'. Use this command instead:\n\n". 7 - " phabricator/ $ ./bin/repository pull ...\n"; 8 - exit(1);
-8
scripts/repository/reparse_all_commit_messages.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "This script is obsolete. Instead, use:\n\n". 5 - " $ reparse.php --all <repository_name> --message\n\n". 6 - "See that script for more options.\n"; 7 - exit(1); 8 -
-5
scripts/search/index_one_commit.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "Use 'bin/search index rXnnnnnn' instead of this script.\n"; 5 - exit(1);
-5
scripts/search/reindex_all_users.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "Use 'bin/search index --type USER' instead of this script.\n"; 5 - die(1);
-5
scripts/search/reindex_everything.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "Use 'bin/search index --all' instead of this script.\n"; 5 - die(1);
-10
scripts/sql/upgrade_schema.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - echo "This script has been replaced by 'phabricator/bin/storage'.\n\n". 5 - "Run:\n\n". 6 - " phabricator/bin $ ./storage help\n\n". 7 - "...for help, or:\n\n". 8 - " phabricator/bin $ ./storage upgrade\n\n". 9 - "...to upgrade storage.\n\n"; 10 - exit(1);
+2 -124
scripts/util/purge_cache.php
··· 1 1 #!/usr/bin/env php 2 2 <?php 3 3 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);
+4
src/__phutil_library_map__.php
··· 807 807 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', 808 808 'PhabricatorButtonsExample' => 'applications/uiexample/examples/PhabricatorButtonsExample.php', 809 809 'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php', 810 + 'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php', 811 + 'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php', 810 812 'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php', 811 813 'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/PhabricatorCalendarBrowseController.php', 812 814 'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php', ··· 2575 2577 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 2576 2578 'PhabricatorButtonsExample' => 'PhabricatorUIExample', 2577 2579 'PhabricatorCacheDAO' => 'PhabricatorLiskDAO', 2580 + 'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorSearchManagementWorkflow', 2581 + 'PhabricatorCacheManagementWorkflow' => 'PhutilArgumentWorkflow', 2578 2582 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', 2579 2583 'PhabricatorCalendarController' => 'PhabricatorController', 2580 2584 'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO',
+99
src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php
··· 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 + }
+10
src/applications/cache/management/PhabricatorCacheManagementWorkflow.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorCacheManagementWorkflow 4 + extends PhutilArgumentWorkflow { 5 + 6 + final public function isExecutable() { 7 + return true; 8 + } 9 + 10 + }