Permalink
Browse files

Support deleting individual changeset

Summary:
add support in purge_cache.php. We might want to add support
for maniphest comments and differential comments later.

Test Plan:
- purging all worked
- purging individual changeset worked
- when input is not integer, correct error message reported

Reviewers: epriestley, btrahan, nh

Reviewed By: nh

CC: nh, aran, jungejason, epriestley

Maniphest Tasks: T683

Differential Revision: https://secure.phabricator.com/D1372
  • Loading branch information...
1 parent 12d1379 commit 49cf1ca10c0878394362a586e17e68ca31c118b9 @jungejason jungejason committed Jan 12, 2012
Showing with 37 additions and 12 deletions.
  1. +37 −12 scripts/util/purge_cache.php
@@ -2,7 +2,7 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,15 +32,25 @@
usage("Specify which caches you want to purge.");
}
-foreach ($args as $arg) {
- switch ($arg) {
+$changesets = array();
+$len = count($args);
+for ($ii = 0; $ii < $len; $ii++) {
+ switch ($args[$ii]) {
case '--all':
$purge_changesets = true;
$purge_differential = true;
$purge_maniphest = 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;
@@ -51,17 +61,27 @@
case '--help':
return help();
default:
- return usage("Unrecognized argument '{$arg}'.");
+ return usage("Unrecognized argument '{$args[$ii]}'.");
}
}
if ($purge_changesets) {
- echo "Purging changeset cache...\n";
$table = new DifferentialChangeset();
- queryfx(
- $table->establishConnection('w'),
- 'TRUNCATE TABLE %T',
- DifferentialChangeset::TABLE_CACHE);
+ 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";
}
@@ -98,7 +118,10 @@ function help() {
$help = <<<EOHELP
**SUMMARY**
- **purge_cache.php** [--maniphest] [--differential] [--changesets]
+ **purge_cache.php**
+ [--maniphest]
+ [--differential]
+ [--changesets [changeset_id ...]]
**purge_cache.php** --all
**purge_cache.php** --help
@@ -117,8 +140,10 @@ function help() {
__--all__
Purge all long-lived caches.
- __--changesets__
- Purge Differential changeset render cache.
+ __--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.

0 comments on commit 49cf1ca

Please sign in to comment.