3 final class PhabricatorRepositoryManagementCacheWorkflow
4 extends PhabricatorRepositoryManagementWorkflow
{
6 protected function didConstruct() {
10 '**cache** [__options__] --commit __commit__ --path __path__')
11 ->setSynopsis(pht('Manage the repository graph cache.'))
17 'help' => pht('Specify a commit to look up.'),
22 'help' => pht('Specify a path to look up.'),
27 public function execute(PhutilArgumentParser
$args) {
29 $commit_name = $args->getArg('commit');
30 if ($commit_name === null) {
31 throw new PhutilArgumentUsageException(
33 'Specify a commit to look up with `%s`.',
36 $commit = $this->loadNamedCommit($commit_name);
38 $path_name = $args->getArg('path');
39 if ($path_name === null) {
40 throw new PhutilArgumentUsageException(
42 'Specify a path to look up with `%s`.',
46 $path_map = id(new DiffusionPathIDQuery(array($path_name)))
48 if (empty($path_map[$path_name])) {
49 throw new PhutilArgumentUsageException(
50 pht('Path "%s" is not unknown.', $path_name));
52 $path_id = $path_map[$path_name];
54 $graph_cache = new PhabricatorRepositoryGraphCache();
56 $t_start = microtime(true);
57 $cache_result = $graph_cache->loadLastModifiedCommitID(
60 $t_end = microtime(true);
62 $console = PhutilConsole
::getConsole();
66 pht('Query took %s ms.', new PhutilNumber(1000 * ($t_end - $t_start))));
68 if ($cache_result === false) {
69 $console->writeOut("%s\n", pht('Not found in graph cache.'));
70 } else if ($cache_result === null) {
73 pht('Path not modified in any ancestor commit.'));
75 $last = id(new DiffusionCommitQuery())
76 ->setViewer($this->getViewer())
77 ->withIDs(array($cache_result))
80 throw new Exception(pht('Cache returned bogus result!'));
86 'Path was last changed at %s.',
87 $commit->getRepository()->formatCommitName(
88 $last->getcommitIdentifier())));