Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementCacheWorkflow.php
blob81955f36f3398e02a1fc2b0c328a42242dc9dd8f
1 <?php
3 final class PhabricatorRepositoryManagementCacheWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('cache')
9 ->setExamples(
10 '**cache** [__options__] --commit __commit__ --path __path__')
11 ->setSynopsis(pht('Manage the repository graph cache.'))
12 ->setArguments(
13 array(
14 array(
15 'name' => 'commit',
16 'param' => 'commit',
17 'help' => pht('Specify a commit to look up.'),
19 array(
20 'name' => 'path',
21 'param' => 'path',
22 'help' => pht('Specify a path to look up.'),
24 ));
27 public function execute(PhutilArgumentParser $args) {
29 $commit_name = $args->getArg('commit');
30 if ($commit_name === null) {
31 throw new PhutilArgumentUsageException(
32 pht(
33 'Specify a commit to look up with `%s`.',
34 '--commit'));
36 $commit = $this->loadNamedCommit($commit_name);
38 $path_name = $args->getArg('path');
39 if ($path_name === null) {
40 throw new PhutilArgumentUsageException(
41 pht(
42 'Specify a path to look up with `%s`.',
43 '--path'));
46 $path_map = id(new DiffusionPathIDQuery(array($path_name)))
47 ->loadPathIDs();
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(
58 $commit->getID(),
59 $path_id);
60 $t_end = microtime(true);
62 $console = PhutilConsole::getConsole();
64 $console->writeOut(
65 "%s\n",
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) {
71 $console->writeOut(
72 "%s\n",
73 pht('Path not modified in any ancestor commit.'));
74 } else {
75 $last = id(new DiffusionCommitQuery())
76 ->setViewer($this->getViewer())
77 ->withIDs(array($cache_result))
78 ->executeOne();
79 if (!$last) {
80 throw new Exception(pht('Cache returned bogus result!'));
83 $console->writeOut(
84 "%s\n",
85 pht(
86 'Path was last changed at %s.',
87 $commit->getRepository()->formatCommitName(
88 $last->getcommitIdentifier())));
91 return 0;