1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +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:
epriestley 2014-04-20 11:54:50 -07:00
parent 230fce735e
commit a4f975ef3e
6 changed files with 40 additions and 84 deletions

View file

@ -28,6 +28,12 @@ final class ConduitAPI_releeph_request_Method
protected function execute(ConduitAPIRequest $request) {
$user = $request->getUser();
$viewer_handle = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs(array($user->getPHID()))
->executeOne();
$branch_phid = $request->getValue('branchPHID');
$releeph_branch = id(new ReleephBranch())
->loadOneWhere('phid = %s', $branch_phid);
@ -131,15 +137,7 @@ final class ConduitAPI_releeph_request_Method
$editor->applyTransactions($releeph_request, $xactions);
}
$releeph_branch->populateReleephRequestHandles(
$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());
$url = PhabricatorEnv::getProductionURI('/Y'.$releeph_request->getID());
$results[$thing] = array(
'thing' => $thing,
'branch' => $releeph_branch->getDisplayNameWithDetail(),
@ -147,7 +145,7 @@ final class ConduitAPI_releeph_request_Method
'commitID' => $commit->getCommitIdentifier(),
'url' => $url,
'requestID' => $releeph_request->getID(),
'requestor' => $requestor,
'requestor' => $viewer_handle->getName(),
'requestTime' => $releeph_request->getDateCreated(),
'existing' => $existing_releeph_request !== null,
);

View file

@ -18,8 +18,8 @@ final class ConduitAPI_releephwork_nextrequest_Method
public function defineParamTypes() {
return array(
'branchPHID' => 'required int',
'seen' => 'required list<string, bool>',
'branchPHID' => 'required phid',
'seen' => 'required map<string, bool>',
);
}
@ -35,6 +35,7 @@ final class ConduitAPI_releephwork_nextrequest_Method
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$seen = $request->getValue('seen');
$branch = id(new ReleephBranch())
@ -45,7 +46,11 @@ final class ConduitAPI_releephwork_nextrequest_Method
$needs_pick = 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) {
$phid = $candidate->getPHID();

View file

@ -178,8 +178,19 @@ final class ReleephRequestEditController extends ReleephBranchController {
}
}
$branch->populateReleephRequestHandles($viewer, array($pull));
$handles = $pull->getHandles();
$handle_phids = array(
$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 = '';
if ($is_edit) {

View file

@ -11,24 +11,18 @@ final class ReleephBranchCommitFieldSpecification
return 'Commit';
}
public function getRequiredHandlePHIDsForPropertyView() {
$pull = $this->getReleephRequest();
if ($pull->getCommitPHID()) {
return array($pull->getCommitPHID());
}
return array();
}
public function renderPropertyViewValue(array $handles) {
$rr = $this->getReleephRequest();
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;
return $this->renderHandleList($handles);
}
}

View file

@ -109,46 +109,6 @@ final class ReleephBranch extends ReleephDAO
'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() {
return $this->getIsActive();
}

View file

@ -20,14 +20,10 @@ final class ReleephRequest extends ReleephDAO
protected $commitIdentifier;
protected $commitPHID;
// Pre-populated handles that we'll bulk load in ReleephBranch
private $handles = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
private $branch = self::ATTACHABLE;
/* -( Constants and helper methods )--------------------------------------- */
const INTENT_WANT = 'want';
@ -160,14 +156,6 @@ final class ReleephRequest extends ReleephDAO
/* -( 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) {
return idx($this->getDetails(), $key, $default);