mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-08 22:01:03 +01:00
Make DifferentialRevisionQuery policy-aware
Summary: Ref T603. Ref T2625. Makes `DifferentialRevisionQuery` do policy checks. Note that it still uses inefficient offset-based paging, but it's rare to page through revisions. I'll switch to cursor paging in a future diff. Test Plan: Viewed a bunch of Differential interfaces, home page, etc. This shouldn't actually materially impact anything. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603, T2625 Differential Revision: https://secure.phabricator.com/D6344
This commit is contained in:
parent
58884b94dc
commit
0c2e38e81c
1 changed files with 32 additions and 86 deletions
|
@ -12,7 +12,8 @@
|
|||
* @task exec Query Execution
|
||||
* @task internal Internals
|
||||
*/
|
||||
final class DifferentialRevisionQuery {
|
||||
final class DifferentialRevisionQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $pathIDs = array();
|
||||
|
||||
|
@ -50,24 +51,11 @@ final class DifferentialRevisionQuery {
|
|||
*/
|
||||
const ORDER_PATH_MODIFIED = 'order-path-modified';
|
||||
|
||||
private $limit = 1000;
|
||||
private $offset = 0;
|
||||
|
||||
private $needRelationships = false;
|
||||
private $needActiveDiffs = false;
|
||||
private $needDiffIDs = false;
|
||||
private $needCommitPHIDs = false;
|
||||
private $needHashes = false;
|
||||
private $viewer;
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getViewer() {
|
||||
return $this->viewer;
|
||||
}
|
||||
|
||||
|
||||
/* -( Query Configuration )------------------------------------------------ */
|
||||
|
@ -267,32 +255,6 @@ final class DifferentialRevisionQuery {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set result limit. If unspecified, defaults to 1000.
|
||||
*
|
||||
* @param int Result limit.
|
||||
* @return this
|
||||
* @task config
|
||||
*/
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set result offset. If unspecified, defaults to 0.
|
||||
*
|
||||
* @param int Result offset.
|
||||
* @return this
|
||||
* @task config
|
||||
*/
|
||||
public function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set whether or not the query will load and attach relationships.
|
||||
*
|
||||
|
@ -372,47 +334,49 @@ final class DifferentialRevisionQuery {
|
|||
* @return list List of matching DifferentialRevision objects.
|
||||
* @task exec
|
||||
*/
|
||||
public function execute() {
|
||||
public function loadPage() {
|
||||
$table = new DifferentialRevision();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = $this->loadData();
|
||||
|
||||
$revisions = $table->loadAllFromArray($data);
|
||||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
if ($revisions) {
|
||||
if ($this->needRelationships) {
|
||||
$this->loadRelationships($conn_r, $revisions);
|
||||
}
|
||||
public function willFilterPage(array $revisions) {
|
||||
if (!$revisions) {
|
||||
return $revisions;
|
||||
}
|
||||
|
||||
if ($this->needCommitPHIDs) {
|
||||
$this->loadCommitPHIDs($conn_r, $revisions);
|
||||
}
|
||||
$table = new DifferentialRevision();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$need_active = $this->needActiveDiffs;
|
||||
$need_ids = $need_active ||
|
||||
$this->needDiffIDs;
|
||||
if ($this->needRelationships) {
|
||||
$this->loadRelationships($conn_r, $revisions);
|
||||
}
|
||||
|
||||
if ($need_ids) {
|
||||
$this->loadDiffIDs($conn_r, $revisions);
|
||||
}
|
||||
if ($this->needCommitPHIDs) {
|
||||
$this->loadCommitPHIDs($conn_r, $revisions);
|
||||
}
|
||||
|
||||
if ($need_active) {
|
||||
$this->loadActiveDiffs($conn_r, $revisions);
|
||||
}
|
||||
$need_active = $this->needActiveDiffs;
|
||||
$need_ids = $need_active || $this->needDiffIDs;
|
||||
|
||||
if ($this->needHashes) {
|
||||
$this->loadHashes($conn_r, $revisions);
|
||||
}
|
||||
if ($need_ids) {
|
||||
$this->loadDiffIDs($conn_r, $revisions);
|
||||
}
|
||||
|
||||
if ($need_active) {
|
||||
$this->loadActiveDiffs($conn_r, $revisions);
|
||||
}
|
||||
|
||||
if ($this->needHashes) {
|
||||
$this->loadHashes($conn_r, $revisions);
|
||||
}
|
||||
|
||||
return $revisions;
|
||||
}
|
||||
|
||||
public function executeOne() {
|
||||
return head($this->execute());
|
||||
}
|
||||
|
||||
private function loadData() {
|
||||
$table = new DifferentialRevision();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -513,18 +477,6 @@ final class DifferentialRevisionQuery {
|
|||
$limit);
|
||||
}
|
||||
|
||||
private function buildLimitClause(AphrontDatabaseConnection $conn_r) {
|
||||
$limit = '';
|
||||
if ($this->offset || $this->limit) {
|
||||
$limit = qsprintf(
|
||||
$conn_r,
|
||||
'LIMIT %d, %d',
|
||||
(int)$this->offset,
|
||||
$this->limit);
|
||||
}
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
/* -( Internals )---------------------------------------------------------- */
|
||||
|
||||
|
@ -723,13 +675,8 @@ final class DifferentialRevisionQuery {
|
|||
"Unknown revision status filter constant '{$this->status}'!");
|
||||
}
|
||||
|
||||
if ($where) {
|
||||
$where = 'WHERE '.implode(' AND ', $where);
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
|
||||
return $where;
|
||||
$where[] = $this->buildPagingCLause($conn_r);
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
||||
|
@ -741,8 +688,7 @@ final class DifferentialRevisionQuery {
|
|||
$this->pathIDs,
|
||||
$this->ccs,
|
||||
$this->reviewers,
|
||||
$this->subscribers,
|
||||
$this->responsibles);
|
||||
$this->subscribers);
|
||||
|
||||
$needs_distinct = (count($join_triggers) > 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue