Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
Show All 10 Lines | final class DifferentialRevisionQuery | ||||
private $pathIDs = array(); | private $pathIDs = array(); | ||||
private $authors = array(); | private $authors = array(); | ||||
private $draftAuthors = array(); | private $draftAuthors = array(); | ||||
private $ccs = array(); | private $ccs = array(); | ||||
private $reviewers = array(); | private $reviewers = array(); | ||||
private $revIDs = array(); | private $revIDs = array(); | ||||
private $commitHashes = array(); | private $commitHashes = array(); | ||||
private $commitPHIDs = array(); | |||||
private $phids = array(); | private $phids = array(); | ||||
private $responsibles = array(); | private $responsibles = array(); | ||||
private $branches = array(); | private $branches = array(); | ||||
private $repositoryPHIDs; | private $repositoryPHIDs; | ||||
private $updatedEpochMin; | private $updatedEpochMin; | ||||
private $updatedEpochMax; | private $updatedEpochMax; | ||||
private $statuses; | private $statuses; | ||||
private $isOpen; | private $isOpen; | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | /* -( Query Configuration )------------------------------------------------ */ | ||||
* @return this | * @return this | ||||
* @task config | * @task config | ||||
*/ | */ | ||||
public function withCommitHashes(array $commit_hashes) { | public function withCommitHashes(array $commit_hashes) { | ||||
$this->commitHashes = $commit_hashes; | $this->commitHashes = $commit_hashes; | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* Filter results to revisions that have one of the provided PHIDs as | |||||
* commits. Calling this function will clear anything set by previous calls | |||||
* to @{method:withCommitPHIDs}. | |||||
* | |||||
* @param array List of PHIDs of commits | |||||
* @return this | |||||
* @task config | |||||
*/ | |||||
public function withCommitPHIDs(array $commit_phids) { | |||||
$this->commitPHIDs = $commit_phids; | |||||
return $this; | |||||
} | |||||
public function withStatuses(array $statuses) { | public function withStatuses(array $statuses) { | ||||
$this->statuses = $statuses; | $this->statuses = $statuses; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withIsOpen($is_open) { | public function withIsOpen($is_open) { | ||||
$this->isOpen = $is_open; | $this->isOpen = $is_open; | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | protected function willFilterPage(array $revisions) { | ||||
if (!$revisions) { | if (!$revisions) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$table = new DifferentialRevision(); | $table = new DifferentialRevision(); | ||||
$conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
if ($this->needCommitPHIDs) { | if ($this->needCommitPHIDs) { | ||||
$this->loadCommitPHIDs($conn_r, $revisions); | $this->loadCommitPHIDs($revisions); | ||||
} | } | ||||
$need_active = $this->needActiveDiffs; | $need_active = $this->needActiveDiffs; | ||||
$need_ids = $need_active || $this->needDiffIDs; | $need_ids = $need_active || $this->needDiffIDs; | ||||
if ($need_ids) { | if ($need_ids) { | ||||
$this->loadDiffIDs($conn_r, $revisions); | $this->loadDiffIDs($conn_r, $revisions); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | if ($this->draftAuthors) { | ||||
'JOIN %T has_draft ON has_draft.srcPHID = r.phid | 'JOIN %T has_draft ON has_draft.srcPHID = r.phid | ||||
AND has_draft.type = %s | AND has_draft.type = %s | ||||
AND has_draft.dstPHID IN (%Ls)', | AND has_draft.dstPHID IN (%Ls)', | ||||
PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
PhabricatorObjectHasDraftEdgeType::EDGECONST, | PhabricatorObjectHasDraftEdgeType::EDGECONST, | ||||
$this->draftAuthors); | $this->draftAuthors); | ||||
} | } | ||||
if ($this->commitPHIDs) { | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'JOIN %T commits ON commits.revisionID = r.id', | |||||
DifferentialRevision::TABLE_COMMIT); | |||||
} | |||||
$joins[] = $this->buildJoinClauseParts($conn); | $joins[] = $this->buildJoinClauseParts($conn); | ||||
return $this->formatJoinClause($conn, $joins); | return $this->formatJoinClause($conn, $joins); | ||||
} | } | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if ($this->commitHashes) { | ||||
'(hash_rel.type = %s AND hash_rel.hash = %s)', | '(hash_rel.type = %s AND hash_rel.hash = %s)', | ||||
$type, | $type, | ||||
$hash); | $hash); | ||||
} | } | ||||
$hash_clauses = qsprintf($conn, '%LO', $hash_clauses); | $hash_clauses = qsprintf($conn, '%LO', $hash_clauses); | ||||
$where[] = $hash_clauses; | $where[] = $hash_clauses; | ||||
} | } | ||||
if ($this->commitPHIDs) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'commits.commitPHID IN (%Ls)', | |||||
$this->commitPHIDs); | |||||
} | |||||
if ($this->phids) { | if ($this->phids) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'r.phid IN (%Ls)', | 'r.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->branches) { | if ($this->branches) { | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
protected function newPagingMapFromPartialObject($object) { | protected function newPagingMapFromPartialObject($object) { | ||||
return array( | return array( | ||||
'id' => (int)$object->getID(), | 'id' => (int)$object->getID(), | ||||
'updated' => (int)$object->getDateModified(), | 'updated' => (int)$object->getDateModified(), | ||||
); | ); | ||||
} | } | ||||
private function loadCommitPHIDs($conn_r, array $revisions) { | private function loadCommitPHIDs(array $revisions) { | ||||
assert_instances_of($revisions, 'DifferentialRevision'); | assert_instances_of($revisions, 'DifferentialRevision'); | ||||
$commit_phids = queryfx_all( | |||||
$conn_r, | if (!$revisions) { | ||||
'SELECT * FROM %T WHERE revisionID IN (%Ld)', | return; | ||||
DifferentialRevision::TABLE_COMMIT, | } | ||||
mpull($revisions, 'getID')); | |||||
$commit_phids = igroup($commit_phids, 'revisionID'); | $revisions = mpull($revisions, null, 'getPHID'); | ||||
foreach ($revisions as $revision) { | |||||
$phids = idx($commit_phids, $revision->getID(), array()); | $edge_query = id(new PhabricatorEdgeQuery()) | ||||
$phids = ipull($phids, 'commitPHID'); | ->withSourcePHIDs(array_keys($revisions)) | ||||
$revision->attachCommitPHIDs($phids); | ->withEdgeTypes( | ||||
array( | |||||
DifferentialRevisionHasCommitEdgeType::EDGECONST, | |||||
)); | |||||
$edge_query->execute(); | |||||
foreach ($revisions as $phid => $revision) { | |||||
$commit_phids = $edge_query->getDestinationPHIDs(array($phid)); | |||||
$revision->attachCommitPHIDs($commit_phids); | |||||
} | } | ||||
} | } | ||||
private function loadDiffIDs($conn_r, array $revisions) { | private function loadDiffIDs($conn_r, array $revisions) { | ||||
assert_instances_of($revisions, 'DifferentialRevision'); | assert_instances_of($revisions, 'DifferentialRevision'); | ||||
$diff_table = new DifferentialDiff(); | $diff_table = new DifferentialDiff(); | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |