mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
Modernize Differential paging/ordering
Summary: Ref T7803. Move Differential off getPagingColumn() / getReversePaging(). Test Plan: Paged Differential results. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7803 Differential Revision: https://secure.phabricator.com/D12362
This commit is contained in:
parent
9b5198f463
commit
51dabc5007
1 changed files with 37 additions and 66 deletions
|
@ -41,7 +41,6 @@ final class DifferentialRevisionQuery
|
||||||
private $updatedEpochMin;
|
private $updatedEpochMin;
|
||||||
private $updatedEpochMax;
|
private $updatedEpochMax;
|
||||||
|
|
||||||
private $order = 'order-modified';
|
|
||||||
const ORDER_MODIFIED = 'order-modified';
|
const ORDER_MODIFIED = 'order-modified';
|
||||||
const ORDER_CREATED = 'order-created';
|
const ORDER_CREATED = 'order-created';
|
||||||
|
|
||||||
|
@ -261,7 +260,17 @@ final class DifferentialRevisionQuery
|
||||||
* @task config
|
* @task config
|
||||||
*/
|
*/
|
||||||
public function setOrder($order_constant) {
|
public function setOrder($order_constant) {
|
||||||
$this->order = $order_constant;
|
switch ($order_constant) {
|
||||||
|
case self::ORDER_CREATED:
|
||||||
|
$this->setOrderVector(array('id'));
|
||||||
|
break;
|
||||||
|
case self::ORDER_MODIFIED:
|
||||||
|
$this->setOrderVector(array('updated', 'id'));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception(pht('Unknown order "%s".', $order_constant));
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,72 +862,34 @@ final class DifferentialRevisionQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildPagingClause(AphrontDatabaseConnection $conn_r) {
|
protected function getDefaultOrderVector() {
|
||||||
$default = parent::buildPagingClause($conn_r);
|
return array('updated', 'id');
|
||||||
|
|
||||||
$before_id = $this->getBeforeID();
|
|
||||||
$after_id = $this->getAfterID();
|
|
||||||
|
|
||||||
if (!$before_id && !$after_id) {
|
|
||||||
return $default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($before_id) {
|
public function getOrderableColumns() {
|
||||||
$cursor = $this->loadCursorObject($before_id);
|
$primary = ($this->buildingGlobalOrder ? null : 'r');
|
||||||
} else {
|
|
||||||
$cursor = $this->loadCursorObject($after_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$cursor) {
|
return array(
|
||||||
return null;
|
'id' => array(
|
||||||
}
|
'table' => $primary,
|
||||||
|
|
||||||
$columns = array();
|
|
||||||
|
|
||||||
switch ($this->order) {
|
|
||||||
case self::ORDER_CREATED:
|
|
||||||
return $default;
|
|
||||||
case self::ORDER_MODIFIED:
|
|
||||||
$columns[] = array(
|
|
||||||
'table' => 'r',
|
|
||||||
'column' => 'dateModified',
|
|
||||||
'value' => $cursor->getDateModified(),
|
|
||||||
'type' => 'int',
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$columns[] = array(
|
|
||||||
'table' => 'r',
|
|
||||||
'column' => 'id',
|
'column' => 'id',
|
||||||
'value' => $cursor->getID(),
|
|
||||||
'type' => 'int',
|
'type' => 'int',
|
||||||
|
'unique' => true,
|
||||||
|
),
|
||||||
|
'updated' => array(
|
||||||
|
'table' => $primary,
|
||||||
|
'column' => 'dateModified',
|
||||||
|
'type' => 'int',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->buildPagingClauseFromMultipleColumns(
|
|
||||||
$conn_r,
|
|
||||||
$columns,
|
|
||||||
array(
|
|
||||||
'reversed' => (bool)($before_id xor $this->getReversePaging()),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPagingColumn() {
|
protected function getPagingValueMap($cursor, array $keys) {
|
||||||
$is_global = $this->buildingGlobalOrder;
|
$revision = $this->loadCursorObject($cursor);
|
||||||
switch ($this->order) {
|
return array(
|
||||||
case self::ORDER_MODIFIED:
|
'id' => $revision->getID(),
|
||||||
if ($is_global) {
|
'updated' => $revision->getDateModified(),
|
||||||
return 'dateModified';
|
);
|
||||||
}
|
|
||||||
return 'r.dateModified';
|
|
||||||
case self::ORDER_CREATED:
|
|
||||||
if ($is_global) {
|
|
||||||
return 'id';
|
|
||||||
}
|
|
||||||
return 'r.id';
|
|
||||||
default:
|
|
||||||
throw new Exception("Unknown query order constant '{$this->order}'.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadRelationships($conn_r, array $revisions) {
|
private function loadRelationships($conn_r, array $revisions) {
|
||||||
|
|
Loading…
Reference in a new issue