mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Remove indirect loads of Differential revisions from Releeph requests
Summary: Ref T3551. Currently, there are many layers of indirection between pull requests and revisions. After D8822, revisions and other types of requested objects are recorded directly on the request. This allows us to simplify data access and querying. A lot of stuff here is doing `instanceof` checks to keep APIs stable, but most of those can go away in the long run. Test Plan: - Browsed requests. - Verified revision-dependent fields (like "Revision", "Size", "Churn") still render correctly. - Called `releeph.queryrequests`. - Called `releephwork.nextrequest`. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3551 Differential Revision: https://secure.phabricator.com/D8824
This commit is contained in:
parent
65913162e7
commit
28696d08ac
8 changed files with 75 additions and 85 deletions
|
@ -37,7 +37,7 @@ final class ConduitAPI_releeph_queryrequests_Method
|
||||||
$query->setViewer($conduit_request->getUser());
|
$query->setViewer($conduit_request->getUser());
|
||||||
|
|
||||||
if ($revision_phids) {
|
if ($revision_phids) {
|
||||||
$query->withRevisionPHIDs($revision_phids);
|
$query->withRequestedObjectPHIDs($revision_phids);
|
||||||
} else if ($requested_commit_phids) {
|
} else if ($requested_commit_phids) {
|
||||||
$query->withRequestedCommitPHIDs($requested_commit_phids);
|
$query->withRequestedCommitPHIDs($requested_commit_phids);
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,14 @@ final class ConduitAPI_releeph_queryrequests_Method
|
||||||
$branch = $releephRequest->getBranch();
|
$branch = $releephRequest->getBranch();
|
||||||
|
|
||||||
$request_commit_phid = $releephRequest->getRequestCommitPHID();
|
$request_commit_phid = $releephRequest->getRequestCommitPHID();
|
||||||
$revisionPHID =
|
|
||||||
$query->getRevisionPHID($request_commit_phid);
|
$object = $releephRequest->getRequestedObject();
|
||||||
|
if ($object instanceof DifferentialRevision) {
|
||||||
|
$object_phid = $object->getPHID();
|
||||||
|
} else {
|
||||||
|
$object_phid = null;
|
||||||
|
}
|
||||||
|
|
||||||
$status = $releephRequest->getStatus();
|
$status = $releephRequest->getStatus();
|
||||||
$statusName = ReleephRequestStatus::getStatusDescriptionFor($status);
|
$statusName = ReleephRequestStatus::getStatusDescriptionFor($status);
|
||||||
$url = PhabricatorEnv::getProductionURI('/RQ'.$releephRequest->getID());
|
$url = PhabricatorEnv::getProductionURI('/RQ'.$releephRequest->getID());
|
||||||
|
@ -58,7 +64,7 @@ final class ConduitAPI_releeph_queryrequests_Method
|
||||||
'branchBasename' => $branch->getBasename(),
|
'branchBasename' => $branch->getBasename(),
|
||||||
'branchSymbolic' => $branch->getSymbolicName(),
|
'branchSymbolic' => $branch->getSymbolicName(),
|
||||||
'requestID' => $releephRequest->getID(),
|
'requestID' => $releephRequest->getID(),
|
||||||
'revisionPHID' => $revisionPHID,
|
'revisionPHID' => $object_phid,
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'statusName' => $statusName,
|
'statusName' => $statusName,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
|
|
|
@ -116,7 +116,14 @@ final class ConduitAPI_releephwork_nextrequest_Method
|
||||||
|
|
||||||
$diff_phid = null;
|
$diff_phid = null;
|
||||||
$diff_rev_id = null;
|
$diff_rev_id = null;
|
||||||
$diff_rev = $releeph_request->loadDifferentialRevision();
|
|
||||||
|
$requested_object = $releeph_request->getRequestedObject();
|
||||||
|
if ($requested_object instanceof DifferentialRevision) {
|
||||||
|
$diff_rev = $requested_object;
|
||||||
|
} else {
|
||||||
|
$diff_rev = null;
|
||||||
|
}
|
||||||
|
|
||||||
if ($diff_rev) {
|
if ($diff_rev) {
|
||||||
$diff_phid = $diff_rev->getPHID();
|
$diff_phid = $diff_rev->getPHID();
|
||||||
$phids[] = $diff_phid;
|
$phids[] = $diff_phid;
|
||||||
|
|
|
@ -19,13 +19,13 @@ final class ReleephDependsOnFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDependentRevisionPHIDs() {
|
private function getDependentRevisionPHIDs() {
|
||||||
$revision = $this
|
$requested_object = $this->getObject()->getRequestedObjectPHID();
|
||||||
->getReleephRequest()
|
if (!($requested_object instanceof DifferentialRevision)) {
|
||||||
->loadDifferentialRevision();
|
|
||||||
if (!$revision) {
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$revision = $requested_object;
|
||||||
|
|
||||||
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
$revision->getPHID(),
|
$revision->getPHID(),
|
||||||
PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV);
|
PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV);
|
||||||
|
|
|
@ -17,15 +17,14 @@ final class ReleephDiffChurnFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
public function renderPropertyViewValue(array $handles) {
|
||||||
$diff_rev = $this->getReleephRequest()->loadDifferentialRevision();
|
$requested_object = $this->getObject()->getRequestedObject();
|
||||||
if (!$diff_rev) {
|
if (!($requested_object instanceof DifferentialRevision)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
$diff_rev = $requested_object;
|
||||||
$diff_rev = $this->getReleephRequest()->loadDifferentialRevision();
|
|
||||||
|
|
||||||
$xactions = id(new DifferentialTransactionQuery())
|
$xactions = id(new DifferentialTransactionQuery())
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
->setViewer($this->getViewer())
|
||||||
->withObjectPHIDs(array($diff_rev->getPHID()))
|
->withObjectPHIDs(array($diff_rev->getPHID()))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,11 @@ final class ReleephDiffSizeFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
public function renderPropertyViewValue(array $handles) {
|
||||||
$diff_rev = $this->getReleephRequest()->loadDifferentialRevision();
|
$requested_object = $this->getObject()->getRequestedObject();
|
||||||
if (!$diff_rev) {
|
if (!($requested_object instanceof DifferentialRevision)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
$diff_rev = $requested_object;
|
||||||
|
|
||||||
$diffs = $diff_rev->loadRelatives(
|
$diffs = $diff_rev->loadRelatives(
|
||||||
new DifferentialDiff(),
|
new DifferentialDiff(),
|
||||||
|
|
|
@ -12,14 +12,14 @@ final class ReleephRevisionFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequiredHandlePHIDsForPropertyView() {
|
public function getRequiredHandlePHIDsForPropertyView() {
|
||||||
$phids = array();
|
$requested_object = $this->getObject()->getRequestedObjectPHID();
|
||||||
|
if (!($requested_object instanceof DifferentialRevision)) {
|
||||||
$phid = $this->getReleephRequest()->loadRequestCommitDiffPHID();
|
return array();
|
||||||
if ($phid) {
|
|
||||||
$phids[] = $phid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $phids;
|
return array(
|
||||||
|
$requested_object->getPHID(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
public function renderPropertyViewValue(array $handles) {
|
||||||
|
|
|
@ -4,13 +4,12 @@ final class ReleephRequestQuery
|
||||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
private $requestedCommitPHIDs;
|
private $requestedCommitPHIDs;
|
||||||
private $commitToRevMap;
|
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $severities;
|
private $severities;
|
||||||
private $requestorPHIDs;
|
private $requestorPHIDs;
|
||||||
private $branchIDs;
|
private $branchIDs;
|
||||||
private $revisionPHIDs;
|
private $requestedObjectPHIDs;
|
||||||
|
|
||||||
const STATUS_ALL = 'status-all';
|
const STATUS_ALL = 'status-all';
|
||||||
const STATUS_OPEN = 'status-open';
|
const STATUS_OPEN = 'status-open';
|
||||||
|
@ -39,14 +38,6 @@ final class ReleephRequestQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRevisionPHID($commit_phid) {
|
|
||||||
if ($this->commitToRevMap) {
|
|
||||||
return idx($this->commitToRevMap, $commit_phid, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withStatus($status) {
|
public function withStatus($status) {
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -67,8 +58,8 @@ final class ReleephRequestQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withRevisionPHIDs(array $revision_phids) {
|
public function withRequestedObjectPHIDs(array $phids) {
|
||||||
$this->revisionPHIDs = $revision_phids;
|
$this->requestedObjectPHIDs = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +80,25 @@ final class ReleephRequestQuery
|
||||||
|
|
||||||
public function willFilterPage(array $requests) {
|
public function willFilterPage(array $requests) {
|
||||||
|
|
||||||
|
// Load requested objects: you must be able to see an object to see
|
||||||
|
// requests for it.
|
||||||
|
$object_phids = mpull($requests, 'getRequestedObjectPHID');
|
||||||
|
$objects = id(new PhabricatorObjectQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->setParentQuery($this)
|
||||||
|
->withPHIDs($object_phids)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
foreach ($requests as $key => $request) {
|
||||||
|
$object_phid = $request->getRequestedObjectPHID();
|
||||||
|
$object = idx($objects, $object_phid);
|
||||||
|
if (!$object) {
|
||||||
|
unset($requests[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$request->attachRequestedObject($object);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->severities) {
|
if ($this->severities) {
|
||||||
$severities = array_fuse($this->severities);
|
$severities = array_fuse($this->severities);
|
||||||
foreach ($requests as $key => $request) {
|
foreach ($requests as $key => $request) {
|
||||||
|
@ -141,64 +151,46 @@ final class ReleephRequestQuery
|
||||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
if ($this->ids) {
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'id IN (%Ld)',
|
'id IN (%Ld)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'phid IN (%Ls)',
|
'phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->branchIDs) {
|
if ($this->branchIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'branchID IN (%Ld)',
|
'branchID IN (%Ld)',
|
||||||
$this->branchIDs);
|
$this->branchIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->requestedCommitPHIDs) {
|
if ($this->requestedCommitPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'requestCommitPHID IN (%Ls)',
|
'requestCommitPHID IN (%Ls)',
|
||||||
$this->requestedCommitPHIDs);
|
$this->requestedCommitPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->requestorPHIDs) {
|
if ($this->requestorPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'requestUserPHID IN (%Ls)',
|
'requestUserPHID IN (%Ls)',
|
||||||
$this->requestorPHIDs);
|
$this->requestorPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->revisionPHIDs) {
|
if ($this->requestedObjectPHIDs !== null) {
|
||||||
$type = PhabricatorEdgeConfig::TYPE_DREV_HAS_COMMIT;
|
|
||||||
|
|
||||||
$edges = id(new PhabricatorEdgeQuery())
|
|
||||||
->withSourcePHIDs($this->revisionPHIDs)
|
|
||||||
->withEdgeTypes(array($type))
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
$this->commitToRevMap = array();
|
|
||||||
foreach ($edges as $revision_phid => $edge) {
|
|
||||||
foreach ($edge[$type] as $commitPHID => $item) {
|
|
||||||
$this->commitToRevMap[$commitPHID] = $revision_phid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->commitToRevMap) {
|
|
||||||
throw new PhabricatorEmptyQueryException("Malformed Revision Phids");
|
|
||||||
}
|
|
||||||
|
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'requestCommitPHID IN (%Ls)',
|
'requestedObjectPHID IN (%Ls)',
|
||||||
array_keys($this->commitToRevMap));
|
$this->requestedObjectPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
|
|
|
@ -30,6 +30,7 @@ final class ReleephRequest extends ReleephDAO
|
||||||
|
|
||||||
private $customFields = self::ATTACHABLE;
|
private $customFields = self::ATTACHABLE;
|
||||||
private $branch = self::ATTACHABLE;
|
private $branch = self::ATTACHABLE;
|
||||||
|
private $requestedObject = self::ATTACHABLE;
|
||||||
|
|
||||||
|
|
||||||
/* -( Constants and helper methods )--------------------------------------- */
|
/* -( Constants and helper methods )--------------------------------------- */
|
||||||
|
@ -105,6 +106,15 @@ final class ReleephRequest extends ReleephDAO
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRequestedObject() {
|
||||||
|
return $this->assertAttached($this->requestedObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachRequestedObject($object) {
|
||||||
|
$this->requestedObject = $object;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
private function calculateStatus() {
|
private function calculateStatus() {
|
||||||
if ($this->shouldBeInBranch()) {
|
if ($this->shouldBeInBranch()) {
|
||||||
if ($this->getInBranch()) {
|
if ($this->getInBranch()) {
|
||||||
|
@ -214,19 +224,6 @@ final class ReleephRequest extends ReleephDAO
|
||||||
return $summary;
|
return $summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadRequestCommitDiffPHID() {
|
|
||||||
$phids = array();
|
|
||||||
$commit = $this->loadPhabricatorRepositoryCommit();
|
|
||||||
if ($commit) {
|
|
||||||
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
||||||
$commit->getPHID(),
|
|
||||||
PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV);
|
|
||||||
}
|
|
||||||
|
|
||||||
return head($phids);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -( Loading external objects )------------------------------------------- */
|
/* -( Loading external objects )------------------------------------------- */
|
||||||
|
|
||||||
public function loadPhabricatorRepositoryCommit() {
|
public function loadPhabricatorRepositoryCommit() {
|
||||||
|
@ -245,18 +242,6 @@ final class ReleephRequest extends ReleephDAO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (T603) Get rid of all this one-off ad-hoc loading.
|
|
||||||
public function loadDifferentialRevision() {
|
|
||||||
$diff_phid = $this->loadRequestCommitDiffPHID();
|
|
||||||
if (!$diff_phid) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->loadOneRelative(
|
|
||||||
new DifferentialRevision(),
|
|
||||||
'phid',
|
|
||||||
'loadRequestCommitDiffPHID');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -( State change helpers )----------------------------------------------- */
|
/* -( State change helpers )----------------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue