From d75d0acba5170dabbdc27502e16b60d9d398ef80 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 20 Apr 2014 11:54:58 -0700 Subject: [PATCH] Remove loadReleephBranch and loadReleephProject from ReleephRequest Summary: Ref T3551. Ref T3549. Mostly unnecessary with modern calls. Test Plan: - Called `releeph.queryrequests`. - Called `releeph.request`. - Called `releephwork.getbranchcommitmessage`. - Called `releephwork.getcommitmessage`. - Called `releephwork.nextrequest`. - Viewed and edited branches and requests. - Made a comment on a request. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3549, T3551 Differential Revision: https://secure.phabricator.com/D8820 --- ...onduitAPI_releeph_queryrequests_Method.php | 6 ++--- .../ConduitAPI_releeph_request_Method.php | 10 ++++--- ...eephwork_getbranchcommitmessage_Method.php | 10 ++++--- ...PI_releephwork_getcommitmessage_Method.php | 12 ++++++--- ...duitAPI_releephwork_nextrequest_Method.php | 8 +++--- ...entialReleephRequestFieldSpecification.php | 12 +++++---- .../ReleephRequestTransactionalEditor.php | 8 +++--- .../releeph/query/ReleephRequestQuery.php | 26 ++++++++++--------- .../releeph/storage/ReleephBranch.php | 14 +++------- .../releeph/storage/ReleephProject.php | 2 +- .../releeph/storage/ReleephRequest.php | 23 +++------------- 11 files changed, 60 insertions(+), 71 deletions(-) diff --git a/src/applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php b/src/applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php index 7180166efb..9683215576 100644 --- a/src/applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php +++ b/src/applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php @@ -45,10 +45,8 @@ final class ConduitAPI_releeph_queryrequests_Method $releephRequests = $query->execute(); foreach ($releephRequests as $releephRequest) { - $branch = $releephRequest->loadReleephBranch(); - if (!$branch) { - continue; - } + $branch = $releephRequest->getBranch(); + $request_commit_phid = $releephRequest->getRequestCommitPHID(); $revisionPHID = $query->getRevisionPHID($request_commit_phid); diff --git a/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php b/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php index bd9d0be36f..762b4a4c9f 100644 --- a/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php +++ b/src/applications/releeph/conduit/ConduitAPI_releeph_request_Method.php @@ -10,7 +10,7 @@ final class ConduitAPI_releeph_request_Method public function defineParamTypes() { return array( 'branchPHID' => 'required string', - 'things' => 'required string', + 'things' => 'required list', 'fields' => 'dict', ); } @@ -35,15 +35,17 @@ final class ConduitAPI_releeph_request_Method ->executeOne(); $branch_phid = $request->getValue('branchPHID'); - $releeph_branch = id(new ReleephBranch()) - ->loadOneWhere('phid = %s', $branch_phid); + $releeph_branch = id(new ReleephBranchQuery()) + ->setViewer($user) + ->withPHIDs(array($branch_phid)) + ->executeOne(); if (!$releeph_branch) { throw id(new ConduitException("ERR_BRANCH"))->setErrorDescription( "No ReleephBranch found with PHID {$branch_phid}!"); } - $releeph_project = $releeph_branch->loadReleephProject(); + $releeph_project = $releeph_branch->getProduct(); // Find the requested commit identifiers $requested_commits = array(); diff --git a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getbranchcommitmessage_Method.php b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getbranchcommitmessage_Method.php index 9095205466..9f5c6932c8 100644 --- a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getbranchcommitmessage_Method.php +++ b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getbranchcommitmessage_Method.php @@ -26,10 +26,14 @@ final class ConduitAPI_releephwork_getbranchcommitmessage_Method } protected function execute(ConduitAPIRequest $request) { - $branch = id(new ReleephBranch()) - ->loadOneWhere('phid = %s', $request->getValue('branchPHID')); + $viewer = $request->getUser(); - $project = $branch->loadReleephProject(); + $branch = id(new ReleephBranchQuery()) + ->setViewer($viewer) + ->withPHIDs(array($request->getValue('branchPHID'))) + ->executeOne(); + + $project = $branch->getProduct(); $creator_phid = $branch->getCreatedByUserPHID(); $cut_phid = $branch->getCutPointCommitPHID(); diff --git a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getcommitmessage_Method.php b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getcommitmessage_Method.php index 3241369579..3bdf941c8d 100644 --- a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getcommitmessage_Method.php +++ b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_getcommitmessage_Method.php @@ -29,8 +29,12 @@ final class ConduitAPI_releephwork_getcommitmessage_Method } protected function execute(ConduitAPIRequest $request) { - $releeph_request = id(new ReleephRequest()) - ->loadOneWhere('phid = %s', $request->getValue('requestPHID')); + $viewer = $request->getUser(); + + $releeph_request = id(new ReleephRequestQuery()) + ->setViewer($viewer) + ->withPHIDs(array($request->getValue('requestPHID'))) + ->executeOne(); $action = $request->getValue('action'); @@ -38,8 +42,8 @@ final class ConduitAPI_releephwork_getcommitmessage_Method $commit_message = array(); - $project = $releeph_request->loadReleephProject(); - $branch = $releeph_request->loadReleephBranch(); + $branch = $releeph_request->getBranch(); + $project = $branch->getProduct(); $selector = $project->getReleephFieldSelector(); $fields = $selector->getFieldSpecifications(); diff --git a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_nextrequest_Method.php b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_nextrequest_Method.php index 125d9f10da..329b3f0451 100644 --- a/src/applications/releeph/conduit/work/ConduitAPI_releephwork_nextrequest_Method.php +++ b/src/applications/releeph/conduit/work/ConduitAPI_releephwork_nextrequest_Method.php @@ -38,10 +38,12 @@ final class ConduitAPI_releephwork_nextrequest_Method $viewer = $request->getUser(); $seen = $request->getValue('seen'); - $branch = id(new ReleephBranch()) - ->loadOneWhere('phid = %s', $request->getValue('branchPHID')); + $branch = id(new ReleephBranchQuery()) + ->setViewer($viewer) + ->withPHIDs(array($request->getValue('branchPHID'))) + ->executeOne(); - $project = $branch->loadReleephProject(); + $project = $branch->getProduct(); $needs_pick = array(); $needs_revert = array(); diff --git a/src/applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php b/src/applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php index 6c94f7cd17..5ae00fb4e6 100644 --- a/src/applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php +++ b/src/applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php @@ -195,7 +195,7 @@ final class DifferentialReleephRequestFieldSpecification { $rqs_seen = array(); $groups = array(); foreach ($releeph_requests as $releeph_request) { - $releeph_branch = $releeph_request->loadReleephBranch(); + $releeph_branch = $releeph_request->getBranch(); $branch_name = $releeph_branch->getName(); $rq_id = 'RQ'.$releeph_request->getID(); @@ -252,7 +252,7 @@ final class DifferentialReleephRequestFieldSpecification { return; } - $releeph_branch = head($releeph_requests)->loadReleephBranch(); + $releeph_branch = head($releeph_requests)->getBranch(); if (!$this->isCommitOnBranch($repo, $commit, $releeph_branch)) { return; } @@ -297,10 +297,12 @@ final class DifferentialReleephRequestFieldSpecification { private function loadReleephRequests() { if (!$this->releephPHIDs) { return array(); - } else { - return id(new ReleephRequest()) - ->loadAllWhere('phid IN (%Ls)', $this->releephPHIDs); } + + return id(new ReleephRequestQuery()) + ->setViewer($this->getViewer()) + ->withPHIDs($this->releephPHIDs) + ->execute(); } private function isCommitOnBranch(PhabricatorRepository $repo, diff --git a/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php b/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php index 56fd690846..775766cc96 100644 --- a/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php +++ b/src/applications/releeph/editor/ReleephRequestTransactionalEditor.php @@ -204,8 +204,8 @@ final class ReleephRequestTransactionalEditor protected function getMailTo(PhabricatorLiskDAO $object) { $to_phids = array(); - $releeph_project = $object->loadReleephProject(); - foreach ($releeph_project->getPushers() as $phid) { + $product = $object->getBranch()->getProduct(); + foreach ($product->getPushers() as $phid) { $to_phids[] = $phid; } @@ -227,8 +227,8 @@ final class ReleephRequestTransactionalEditor $body = parent::buildMailBody($object, $xactions); $rq = $object; - $releeph_branch = $rq->loadReleephBranch(); - $releeph_project = $releeph_branch->loadReleephProject(); + $releeph_branch = $rq->getBranch(); + $releeph_project = $releeph_branch->getProduct(); /** * If any of the events we are emailing about were about a pick failure diff --git a/src/applications/releeph/query/ReleephRequestQuery.php b/src/applications/releeph/query/ReleephRequestQuery.php index 23725de1ec..5108e6361d 100644 --- a/src/applications/releeph/query/ReleephRequestQuery.php +++ b/src/applications/releeph/query/ReleephRequestQuery.php @@ -89,18 +89,6 @@ final class ReleephRequestQuery public function willFilterPage(array $requests) { - // TODO: These should be serviced by the query, but are not currently - // denormalized anywhere. For now, filter them here instead. - - $keep_status = array_fuse($this->getKeepStatusConstants()); - if ($keep_status) { - foreach ($requests as $key => $request) { - if (empty($keep_status[$request->getStatus()])) { - unset($requests[$key]); - } - } - } - if ($this->severities) { $severities = array_fuse($this->severities); foreach ($requests as $key => $request) { @@ -133,6 +121,20 @@ final class ReleephRequestQuery $request->attachBranch($branch); } + // TODO: These should be serviced by the query, but are not currently + // denormalized anywhere. For now, filter them here instead. Note that + // we must perform this filtering *after* querying and attaching branches, + // because request status depends on the product. + + $keep_status = array_fuse($this->getKeepStatusConstants()); + if ($keep_status) { + foreach ($requests as $key => $request) { + if (empty($keep_status[$request->getStatus()])) { + unset($requests[$key]); + } + } + } + return $requests; } diff --git a/src/applications/releeph/storage/ReleephBranch.php b/src/applications/releeph/storage/ReleephBranch.php index be6fc11428..d779af56a8 100644 --- a/src/applications/releeph/storage/ReleephBranch.php +++ b/src/applications/releeph/storage/ReleephBranch.php @@ -94,21 +94,13 @@ final class ReleephBranch extends ReleephDAO public function getURI($path = null) { $components = array( - '/releeph', - rawurlencode($this->loadReleephProject()->getName()), - rawurlencode($this->getBasename()), - $path + '/releeph/branch', + $this->getID(), + $path, ); return implode('/', $components); } - public function loadReleephProject() { - return $this->loadOneRelative( - new ReleephProject(), - 'id', - 'getReleephProjectID'); - } - public function isActive() { return $this->getIsActive(); } diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php index b05dd3f50b..d6b520ac89 100644 --- a/src/applications/releeph/storage/ReleephProject.php +++ b/src/applications/releeph/storage/ReleephProject.php @@ -42,7 +42,7 @@ final class ReleephProject extends ReleephDAO public function getURI($path = null) { $components = array( - '/releeph/project', + '/releeph/product', $this->getID(), $path ); diff --git a/src/applications/releeph/storage/ReleephRequest.php b/src/applications/releeph/storage/ReleephRequest.php index 92f7de87a5..3c5af69850 100644 --- a/src/applications/releeph/storage/ReleephRequest.php +++ b/src/applications/releeph/storage/ReleephRequest.php @@ -52,18 +52,15 @@ final class ReleephRequest extends ReleephDAO * passes on this request. */ public function getPusherIntent() { - $project = $this->loadReleephProject(); - if (!$project) { - return null; - } + $product = $this->getBranch()->getProduct(); - if (!$project->getPushers()) { + if (!$product->getPushers()) { return self::INTENT_WANT; } $found_pusher_want = false; foreach ($this->userIntents as $phid => $intent) { - if ($project->isAuthoritativePHID($phid)) { + if ($product->isAuthoritativePHID($phid)) { if ($intent == self::INTENT_PASS) { return self::INTENT_PASS; } @@ -210,20 +207,6 @@ final class ReleephRequest extends ReleephDAO /* -( Loading external objects )------------------------------------------- */ - public function loadReleephBranch() { - return $this->loadOneRelative( - new ReleephBranch(), - 'id', - 'getBranchID'); - } - - public function loadReleephProject() { - $branch = $this->loadReleephBranch(); - if ($branch) { - return $branch->loadReleephProject(); - } - } - public function loadPhabricatorRepositoryCommit() { return $this->loadOneRelative( new PhabricatorRepositoryCommit(),