mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Remove some ad-hoc handle loads from Releeph
Summary: Ref T3551. Releeph does a bunch of old-school on-object data loading; start cleaning that up. This doesn't change anything, just makes the code more modern/consistent. Test Plan: Edited a request; called `releephwork.nextrequest`. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3551 Differential Revision: https://secure.phabricator.com/D8819
This commit is contained in:
parent
230fce735e
commit
a4f975ef3e
6 changed files with 40 additions and 84 deletions
|
@ -28,6 +28,12 @@ final class ConduitAPI_releeph_request_Method
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
$viewer_handle = id(new PhabricatorHandleQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->withPHIDs(array($user->getPHID()))
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
$branch_phid = $request->getValue('branchPHID');
|
$branch_phid = $request->getValue('branchPHID');
|
||||||
$releeph_branch = id(new ReleephBranch())
|
$releeph_branch = id(new ReleephBranch())
|
||||||
->loadOneWhere('phid = %s', $branch_phid);
|
->loadOneWhere('phid = %s', $branch_phid);
|
||||||
|
@ -131,15 +137,7 @@ final class ConduitAPI_releeph_request_Method
|
||||||
$editor->applyTransactions($releeph_request, $xactions);
|
$editor->applyTransactions($releeph_request, $xactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
$releeph_branch->populateReleephRequestHandles(
|
$url = PhabricatorEnv::getProductionURI('/Y'.$releeph_request->getID());
|
||||||
$user,
|
|
||||||
array($releeph_request));
|
|
||||||
$rq_handles = $releeph_request->getHandles();
|
|
||||||
$requestor_phid = $releeph_request->getRequestUserPHID();
|
|
||||||
$requestor = $rq_handles[$requestor_phid]->getName();
|
|
||||||
|
|
||||||
$url = PhabricatorEnv::getProductionURI('/RQ'.$releeph_request->getID());
|
|
||||||
|
|
||||||
$results[$thing] = array(
|
$results[$thing] = array(
|
||||||
'thing' => $thing,
|
'thing' => $thing,
|
||||||
'branch' => $releeph_branch->getDisplayNameWithDetail(),
|
'branch' => $releeph_branch->getDisplayNameWithDetail(),
|
||||||
|
@ -147,7 +145,7 @@ final class ConduitAPI_releeph_request_Method
|
||||||
'commitID' => $commit->getCommitIdentifier(),
|
'commitID' => $commit->getCommitIdentifier(),
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'requestID' => $releeph_request->getID(),
|
'requestID' => $releeph_request->getID(),
|
||||||
'requestor' => $requestor,
|
'requestor' => $viewer_handle->getName(),
|
||||||
'requestTime' => $releeph_request->getDateCreated(),
|
'requestTime' => $releeph_request->getDateCreated(),
|
||||||
'existing' => $existing_releeph_request !== null,
|
'existing' => $existing_releeph_request !== null,
|
||||||
);
|
);
|
||||||
|
|
|
@ -18,8 +18,8 @@ final class ConduitAPI_releephwork_nextrequest_Method
|
||||||
|
|
||||||
public function defineParamTypes() {
|
public function defineParamTypes() {
|
||||||
return array(
|
return array(
|
||||||
'branchPHID' => 'required int',
|
'branchPHID' => 'required phid',
|
||||||
'seen' => 'required list<string, bool>',
|
'seen' => 'required map<string, bool>',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ final class ConduitAPI_releephwork_nextrequest_Method
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$viewer = $request->getUser();
|
||||||
$seen = $request->getValue('seen');
|
$seen = $request->getValue('seen');
|
||||||
|
|
||||||
$branch = id(new ReleephBranch())
|
$branch = id(new ReleephBranch())
|
||||||
|
@ -45,7 +46,11 @@ final class ConduitAPI_releephwork_nextrequest_Method
|
||||||
$needs_pick = array();
|
$needs_pick = array();
|
||||||
$needs_revert = array();
|
$needs_revert = array();
|
||||||
|
|
||||||
$releeph_requests = $branch->loadReleephRequests($request->getUser());
|
// Load every request ever made for this branch...?!!!
|
||||||
|
$releeph_requests = id(new ReleephRequestQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withBranchIDs(array($branch->getID()))
|
||||||
|
->execute();
|
||||||
|
|
||||||
foreach ($releeph_requests as $candidate) {
|
foreach ($releeph_requests as $candidate) {
|
||||||
$phid = $candidate->getPHID();
|
$phid = $candidate->getPHID();
|
||||||
|
|
|
@ -178,8 +178,19 @@ final class ReleephRequestEditController extends ReleephBranchController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$branch->populateReleephRequestHandles($viewer, array($pull));
|
$handle_phids = array(
|
||||||
$handles = $pull->getHandles();
|
$pull->getRequestUserPHID(),
|
||||||
|
$pull->getRequestCommitPHID(),
|
||||||
|
);
|
||||||
|
$handle_phids = array_filter($handle_phids);
|
||||||
|
if ($handle_phids) {
|
||||||
|
$handles = id(new PhabricatorHandleQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs($handle_phids)
|
||||||
|
->execute();
|
||||||
|
} else {
|
||||||
|
$handles = array();
|
||||||
|
}
|
||||||
|
|
||||||
$age_string = '';
|
$age_string = '';
|
||||||
if ($is_edit) {
|
if ($is_edit) {
|
||||||
|
|
|
@ -11,24 +11,18 @@ final class ReleephBranchCommitFieldSpecification
|
||||||
return 'Commit';
|
return 'Commit';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRequiredHandlePHIDsForPropertyView() {
|
||||||
|
$pull = $this->getReleephRequest();
|
||||||
|
|
||||||
|
if ($pull->getCommitPHID()) {
|
||||||
|
return array($pull->getCommitPHID());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
public function renderPropertyViewValue(array $handles) {
|
||||||
$rr = $this->getReleephRequest();
|
return $this->renderHandleList($handles);
|
||||||
if (!$rr->getInBranch()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$c_phid = $rr->getCommitPHID();
|
|
||||||
$c_id = $rr->getCommitIdentifier();
|
|
||||||
|
|
||||||
if ($c_phid) {
|
|
||||||
$handles = $rr->getHandles();
|
|
||||||
$val = $handles[$c_phid]->renderLink();
|
|
||||||
} else if ($c_id) {
|
|
||||||
$val = $c_id;
|
|
||||||
} else {
|
|
||||||
$val = '???';
|
|
||||||
}
|
|
||||||
return $val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,46 +109,6 @@ final class ReleephBranch extends ReleephDAO
|
||||||
'getReleephProjectID');
|
'getReleephProjectID');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadReleephRequestHandles(PhabricatorUser $user, $reqs) {
|
|
||||||
$phids_to_phetch = array();
|
|
||||||
foreach ($reqs as $rr) {
|
|
||||||
$phids_to_phetch[] = $rr->getRequestCommitPHID();
|
|
||||||
$phids_to_phetch[] = $rr->getRequestUserPHID();
|
|
||||||
$phids_to_phetch[] = $rr->getCommitPHID();
|
|
||||||
|
|
||||||
$intents = $rr->getUserIntents();
|
|
||||||
if ($intents) {
|
|
||||||
foreach ($intents as $user_phid => $intent) {
|
|
||||||
$phids_to_phetch[] = $user_phid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$request_commit = $rr->loadPhabricatorRepositoryCommit();
|
|
||||||
if ($request_commit) {
|
|
||||||
$phids_to_phetch[] = $request_commit->getAuthorPHID();
|
|
||||||
$phids_to_phetch[] = $rr->loadRequestCommitDiffPHID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$handles = id(new PhabricatorHandleQuery())
|
|
||||||
->setViewer($user)
|
|
||||||
->withPHIDs($phids_to_phetch)
|
|
||||||
->execute();
|
|
||||||
return $handles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function populateReleephRequestHandles(PhabricatorUser $user, $reqs) {
|
|
||||||
$handles = $this->loadReleephRequestHandles($user, $reqs);
|
|
||||||
foreach ($reqs as $req) {
|
|
||||||
$req->setHandles($handles);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function loadReleephRequests(PhabricatorUser $user) {
|
|
||||||
$reqs = $this->loadRelatives(new ReleephRequest(), 'branchID');
|
|
||||||
$this->populateReleephRequestHandles($user, $reqs);
|
|
||||||
return $reqs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isActive() {
|
public function isActive() {
|
||||||
return $this->getIsActive();
|
return $this->getIsActive();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,10 @@ final class ReleephRequest extends ReleephDAO
|
||||||
protected $commitIdentifier;
|
protected $commitIdentifier;
|
||||||
protected $commitPHID;
|
protected $commitPHID;
|
||||||
|
|
||||||
// Pre-populated handles that we'll bulk load in ReleephBranch
|
|
||||||
private $handles = self::ATTACHABLE;
|
|
||||||
|
|
||||||
private $customFields = self::ATTACHABLE;
|
private $customFields = self::ATTACHABLE;
|
||||||
private $branch = self::ATTACHABLE;
|
private $branch = self::ATTACHABLE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* -( Constants and helper methods )--------------------------------------- */
|
/* -( Constants and helper methods )--------------------------------------- */
|
||||||
|
|
||||||
const INTENT_WANT = 'want';
|
const INTENT_WANT = 'want';
|
||||||
|
@ -160,14 +156,6 @@ final class ReleephRequest extends ReleephDAO
|
||||||
|
|
||||||
/* -( Helpful accessors )--------------------------------------------------- */
|
/* -( Helpful accessors )--------------------------------------------------- */
|
||||||
|
|
||||||
public function setHandles($handles) {
|
|
||||||
$this->handles = $handles;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHandles() {
|
|
||||||
return $this->assertAttached($this->handles);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDetail($key, $default = null) {
|
public function getDetail($key, $default = null) {
|
||||||
return idx($this->getDetails(), $key, $default);
|
return idx($this->getDetails(), $key, $default);
|
||||||
|
|
Loading…
Reference in a new issue