@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 94 lines 2.6 kB view raw
1<?php 2 3final class PhabricatorRepositoryManagementCacheWorkflow 4 extends PhabricatorRepositoryManagementWorkflow { 5 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.'), 18 ), 19 array( 20 'name' => 'path', 21 'param' => 'path', 22 'help' => pht('Specify a path to look up.'), 23 ), 24 )); 25 } 26 27 public function execute(PhutilArgumentParser $args) { 28 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')); 35 } 36 $commit = $this->loadNamedCommit($commit_name); 37 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')); 44 } 45 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)); 51 } 52 $path_id = $path_map[$path_name]; 53 54 $graph_cache = new PhabricatorRepositoryGraphCache(); 55 56 $t_start = microtime(true); 57 $cache_result = $graph_cache->loadLastModifiedCommitID( 58 $commit->getID(), 59 $path_id); 60 $t_end = microtime(true); 61 62 $console = PhutilConsole::getConsole(); 63 64 $console->writeOut( 65 "%s\n", 66 pht('Query took %s ms.', new PhutilNumber(1000 * ($t_end - $t_start)))); 67 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!')); 81 } 82 83 $console->writeOut( 84 "%s\n", 85 pht( 86 'Path was last changed at %s.', 87 $commit->getRepository()->formatCommitName( 88 $last->getcommitIdentifier()))); 89 } 90 91 return 0; 92 } 93 94}