1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

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
This commit is contained in:
jungejason 2012-01-11 18:11:43 -08:00
parent 12d1379dee
commit 49cf1ca10c

View file

@ -2,7 +2,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,8 +32,10 @@ if (!$args) {
usage("Specify which caches you want to purge."); usage("Specify which caches you want to purge.");
} }
foreach ($args as $arg) { $changesets = array();
switch ($arg) { $len = count($args);
for ($ii = 0; $ii < $len; $ii++) {
switch ($args[$ii]) {
case '--all': case '--all':
$purge_changesets = true; $purge_changesets = true;
$purge_differential = true; $purge_differential = true;
@ -41,6 +43,14 @@ foreach ($args as $arg) {
break; break;
case '--changesets': case '--changesets':
$purge_changesets = true; $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; break;
case '--differential': case '--differential':
$purge_differential = true; $purge_differential = true;
@ -51,17 +61,27 @@ foreach ($args as $arg) {
case '--help': case '--help':
return help(); return help();
default: default:
return usage("Unrecognized argument '{$arg}'."); return usage("Unrecognized argument '{$args[$ii]}'.");
} }
} }
if ($purge_changesets) { if ($purge_changesets) {
echo "Purging changeset cache...\n";
$table = new DifferentialChangeset(); $table = new DifferentialChangeset();
queryfx( if ($changesets) {
$table->establishConnection('w'), echo "Purging changeset cache for changesets ".
'TRUNCATE TABLE %T', implode($changesets, ",")."\n";
DifferentialChangeset::TABLE_CACHE); 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"; echo "Done.\n";
} }
@ -98,7 +118,10 @@ function help() {
$help = <<<EOHELP $help = <<<EOHELP
**SUMMARY** **SUMMARY**
**purge_cache.php** [--maniphest] [--differential] [--changesets] **purge_cache.php**
[--maniphest]
[--differential]
[--changesets [changeset_id ...]]
**purge_cache.php** --all **purge_cache.php** --all
**purge_cache.php** --help **purge_cache.php** --help
@ -117,8 +140,10 @@ function help() {
__--all__ __--all__
Purge all long-lived caches. Purge all long-lived caches.
__--changesets__ __--changesets [changeset_id ...]__
Purge Differential changeset render cache. 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__ __--differential__
Purge Differential comment formatting cache. Purge Differential comment formatting cache.