From e01ceaa07f4c28bc01958fb136caa492e7468bc5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 20 May 2013 10:16:35 -0700 Subject: [PATCH] Provide 'bin/cache', for managing caches Summary: See . 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 --- bin/cache | 1 + scripts/cache/manage_cache.php | 22 +++ scripts/repository/discover.php | 8 -- scripts/repository/parse_one_commit.php | 7 - scripts/repository/pull.php | 8 -- .../reparse_all_commit_messages.php | 8 -- scripts/search/index_one_commit.php | 5 - scripts/search/reindex_all_users.php | 5 - scripts/search/reindex_everything.php | 5 - scripts/sql/upgrade_schema.php | 10 -- scripts/util/purge_cache.php | 126 +----------------- src/__phutil_library_map__.php | 4 + ...habricatorCacheManagementPurgeWorkflow.php | 99 ++++++++++++++ .../PhabricatorCacheManagementWorkflow.php | 10 ++ 14 files changed, 138 insertions(+), 180 deletions(-) create mode 120000 bin/cache create mode 100755 scripts/cache/manage_cache.php delete mode 100755 scripts/repository/discover.php delete mode 100755 scripts/repository/parse_one_commit.php delete mode 100755 scripts/repository/pull.php delete mode 100755 scripts/repository/reparse_all_commit_messages.php delete mode 100755 scripts/search/index_one_commit.php delete mode 100755 scripts/search/reindex_all_users.php delete mode 100755 scripts/search/reindex_everything.php delete mode 100755 scripts/sql/upgrade_schema.php create mode 100644 src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php create mode 100644 src/applications/cache/management/PhabricatorCacheManagementWorkflow.php diff --git a/bin/cache b/bin/cache new file mode 120000 index 0000000000..f3b182e818 --- /dev/null +++ b/bin/cache @@ -0,0 +1 @@ +../scripts/cache/manage_cache.php \ No newline at end of file diff --git a/scripts/cache/manage_cache.php b/scripts/cache/manage_cache.php new file mode 100755 index 0000000000..20c4bc1d84 --- /dev/null +++ b/scripts/cache/manage_cache.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +setTagline('manage mail'); +$args->setSynopsis(<<parseStandardArguments(); + +$workflows = array( + new PhabricatorCacheManagementPurgeWorkflow(), + new PhutilHelpArgumentWorkflow(), +); + +$args->parseWorkflows($workflows); diff --git a/scripts/repository/discover.php b/scripts/repository/discover.php deleted file mode 100755 index e5f2df166b..0000000000 --- a/scripts/repository/discover.php +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env php - --message --change\n\n". - "See that script for more options.\n"; -exit(1); diff --git a/scripts/repository/pull.php b/scripts/repository/pull.php deleted file mode 100755 index 5f716e77d4..0000000000 --- a/scripts/repository/pull.php +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env php - --message\n\n". - "See that script for more options.\n"; -exit(1); - diff --git a/scripts/search/index_one_commit.php b/scripts/search/index_one_commit.php deleted file mode 100755 index 7803caccef..0000000000 --- a/scripts/search/index_one_commit.php +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env php -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 = << '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', diff --git a/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php b/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php new file mode 100644 index 0000000000..cfa29c0b5e --- /dev/null +++ b/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php @@ -0,0 +1,99 @@ +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'); + } + +} diff --git a/src/applications/cache/management/PhabricatorCacheManagementWorkflow.php b/src/applications/cache/management/PhabricatorCacheManagementWorkflow.php new file mode 100644 index 0000000000..661a1ee359 --- /dev/null +++ b/src/applications/cache/management/PhabricatorCacheManagementWorkflow.php @@ -0,0 +1,10 @@ +