@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.

Remove `shouldCreateDiffusionRequest` from Diffusion conduit methods

Summary:
Ref T2683. This has no callsites, and the functionality is covered by the `initFromConduit` flag.

This simplifies the code and reduces then number of internal `diffusion.resolverefs` calls we make on, e.g., the Git repository page from 7 to 2.

Test Plan: Grepped for these symbols.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2683

Differential Revision: https://secure.phabricator.com/D9090

+13 -60
+13 -60
src/applications/diffusion/conduit/ConduitAPI_diffusion_abstractquery_Method.php
··· 23 23 24 24 private $diffusionRequest; 25 25 private $repository; 26 - private $shouldCreateDiffusionRequest = true; 27 26 28 27 protected function setDiffusionRequest(DiffusionRequest $request) { 29 28 $this->diffusionRequest = $request; 30 29 return $this; 31 30 } 31 + 32 32 protected function getDiffusionRequest() { 33 33 return $this->diffusionRequest; 34 34 } 35 35 36 - /** 37 - * A wee bit of magic here. If @{method:shouldCreateDiffusionRequest} 38 - * returns false, this function grabs a repository object based on the 39 - * callsign directly. Otherwise, the repository was loaded when we created a 40 - * @{class:DiffusionRequest}, so this function just pulls it out of the 41 - * @{class:DiffusionRequest}. 42 - * 43 - * @return @{class:PhabricatorRepository} $repository 44 - */ 45 36 protected function getRepository(ConduitAPIRequest $request) { 46 - if (!$this->repository) { 47 - if ($this->shouldCreateDiffusionRequest()) { 48 - $this->repository = $this->getDiffusionRequest()->getRepository(); 49 - } else { 50 - $callsign = $request->getValue('callsign'); 51 - $repository = id(new PhabricatorRepositoryQuery()) 52 - ->setViewer($request->getUser()) 53 - ->withCallsigns(array($callsign)) 54 - ->executeOne(); 55 - if (!$repository) { 56 - throw new ConduitException('ERR-UNKNOWN-REPOSITORY'); 57 - } 58 - $this->repository = $repository; 59 - } 60 - } 61 - return $this->repository; 62 - } 63 - 64 - /** 65 - * You should probably not mess with this unless your conduit method is 66 - * involved with the creation / validation / etc. of 67 - * @{class:DiffusionRequest}s. If you are dealing with 68 - * @{class:DiffusionRequest}, setting this to false should help avoid 69 - * infinite loops. 70 - */ 71 - protected function setShouldCreateDiffusionRequest($should) { 72 - $this->shouldCreateDiffusionRequest = $should; 73 - return $this; 74 - } 75 - private function shouldCreateDiffusionRequest() { 76 - return $this->shouldCreateDiffusionRequest; 37 + return $this->getDiffusionRequest()->getRepository(); 77 38 } 78 39 79 40 final public function defineErrorTypes() { ··· 132 93 * @{method:getResult} should be overridden by subclasses as necessary, e.g. 133 94 * there is a common operation across all version control systems that 134 95 * should occur after @{method:getResult}, like formatting a timestamp. 135 - * 136 - * In the rare cases where one does not want to create a 137 - * @{class:DiffusionRequest} - suppose to avoid infinite loops in the 138 - * creation of a @{class:DiffusionRequest} - make sure to call 139 - * 140 - * $this->setShouldCreateDiffusionRequest(false); 141 - * 142 - * in the constructor of the pertinent Conduit method. 143 96 */ 144 97 final protected function execute(ConduitAPIRequest $request) { 145 - if ($this->shouldCreateDiffusionRequest()) { 146 - $drequest = DiffusionRequest::newFromDictionary( 147 - array( 148 - 'user' => $request->getUser(), 149 - 'callsign' => $request->getValue('callsign'), 150 - 'branch' => $request->getValue('branch'), 151 - 'path' => $request->getValue('path'), 152 - 'commit' => $request->getValue('commit'), 153 - )); 154 - $this->setDiffusionRequest($drequest); 155 - } 98 + $drequest = DiffusionRequest::newFromDictionary( 99 + array( 100 + 'user' => $request->getUser(), 101 + 'callsign' => $request->getValue('callsign'), 102 + 'branch' => $request->getValue('branch'), 103 + 'path' => $request->getValue('path'), 104 + 'commit' => $request->getValue('commit'), 105 + 'initFromConduit' => false, 106 + )); 107 + 108 + $this->setDiffusionRequest($drequest); 156 109 157 110 return $this->getResult($request); 158 111 }