mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 23:10:57 +01:00
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
This commit is contained in:
parent
0ab192d245
commit
7cc9720d60
1 changed files with 13 additions and 60 deletions
|
@ -23,57 +23,18 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
|
||||||
|
|
||||||
private $diffusionRequest;
|
private $diffusionRequest;
|
||||||
private $repository;
|
private $repository;
|
||||||
private $shouldCreateDiffusionRequest = true;
|
|
||||||
|
|
||||||
protected function setDiffusionRequest(DiffusionRequest $request) {
|
protected function setDiffusionRequest(DiffusionRequest $request) {
|
||||||
$this->diffusionRequest = $request;
|
$this->diffusionRequest = $request;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDiffusionRequest() {
|
protected function getDiffusionRequest() {
|
||||||
return $this->diffusionRequest;
|
return $this->diffusionRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A wee bit of magic here. If @{method:shouldCreateDiffusionRequest}
|
|
||||||
* returns false, this function grabs a repository object based on the
|
|
||||||
* callsign directly. Otherwise, the repository was loaded when we created a
|
|
||||||
* @{class:DiffusionRequest}, so this function just pulls it out of the
|
|
||||||
* @{class:DiffusionRequest}.
|
|
||||||
*
|
|
||||||
* @return @{class:PhabricatorRepository} $repository
|
|
||||||
*/
|
|
||||||
protected function getRepository(ConduitAPIRequest $request) {
|
protected function getRepository(ConduitAPIRequest $request) {
|
||||||
if (!$this->repository) {
|
return $this->getDiffusionRequest()->getRepository();
|
||||||
if ($this->shouldCreateDiffusionRequest()) {
|
|
||||||
$this->repository = $this->getDiffusionRequest()->getRepository();
|
|
||||||
} else {
|
|
||||||
$callsign = $request->getValue('callsign');
|
|
||||||
$repository = id(new PhabricatorRepositoryQuery())
|
|
||||||
->setViewer($request->getUser())
|
|
||||||
->withCallsigns(array($callsign))
|
|
||||||
->executeOne();
|
|
||||||
if (!$repository) {
|
|
||||||
throw new ConduitException('ERR-UNKNOWN-REPOSITORY');
|
|
||||||
}
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* You should probably not mess with this unless your conduit method is
|
|
||||||
* involved with the creation / validation / etc. of
|
|
||||||
* @{class:DiffusionRequest}s. If you are dealing with
|
|
||||||
* @{class:DiffusionRequest}, setting this to false should help avoid
|
|
||||||
* infinite loops.
|
|
||||||
*/
|
|
||||||
protected function setShouldCreateDiffusionRequest($should) {
|
|
||||||
$this->shouldCreateDiffusionRequest = $should;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
private function shouldCreateDiffusionRequest() {
|
|
||||||
return $this->shouldCreateDiffusionRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function defineErrorTypes() {
|
final public function defineErrorTypes() {
|
||||||
|
@ -132,17 +93,8 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
|
||||||
* @{method:getResult} should be overridden by subclasses as necessary, e.g.
|
* @{method:getResult} should be overridden by subclasses as necessary, e.g.
|
||||||
* there is a common operation across all version control systems that
|
* there is a common operation across all version control systems that
|
||||||
* should occur after @{method:getResult}, like formatting a timestamp.
|
* should occur after @{method:getResult}, like formatting a timestamp.
|
||||||
*
|
|
||||||
* In the rare cases where one does not want to create a
|
|
||||||
* @{class:DiffusionRequest} - suppose to avoid infinite loops in the
|
|
||||||
* creation of a @{class:DiffusionRequest} - make sure to call
|
|
||||||
*
|
|
||||||
* $this->setShouldCreateDiffusionRequest(false);
|
|
||||||
*
|
|
||||||
* in the constructor of the pertinent Conduit method.
|
|
||||||
*/
|
*/
|
||||||
final protected function execute(ConduitAPIRequest $request) {
|
final protected function execute(ConduitAPIRequest $request) {
|
||||||
if ($this->shouldCreateDiffusionRequest()) {
|
|
||||||
$drequest = DiffusionRequest::newFromDictionary(
|
$drequest = DiffusionRequest::newFromDictionary(
|
||||||
array(
|
array(
|
||||||
'user' => $request->getUser(),
|
'user' => $request->getUser(),
|
||||||
|
@ -150,9 +102,10 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
|
||||||
'branch' => $request->getValue('branch'),
|
'branch' => $request->getValue('branch'),
|
||||||
'path' => $request->getValue('path'),
|
'path' => $request->getValue('path'),
|
||||||
'commit' => $request->getValue('commit'),
|
'commit' => $request->getValue('commit'),
|
||||||
|
'initFromConduit' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->setDiffusionRequest($drequest);
|
$this->setDiffusionRequest($drequest);
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getResult($request);
|
return $this->getResult($request);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue