1
0
Fork 0
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:
epriestley 2015-04-11 20:26:20 -07:00
parent 9b5198f463
commit 51dabc5007

View file

@ -41,7 +41,6 @@ final class DifferentialRevisionQuery
private $updatedEpochMin;
private $updatedEpochMax;
private $order = 'order-modified';
const ORDER_MODIFIED = 'order-modified';
const ORDER_CREATED = 'order-created';
@ -261,7 +260,17 @@ final class DifferentialRevisionQuery
* @task config
*/
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;
}
@ -853,72 +862,34 @@ final class DifferentialRevisionQuery
}
}
protected function buildPagingClause(AphrontDatabaseConnection $conn_r) {
$default = parent::buildPagingClause($conn_r);
$before_id = $this->getBeforeID();
$after_id = $this->getAfterID();
if (!$before_id && !$after_id) {
return $default;
protected function getDefaultOrderVector() {
return array('updated', 'id');
}
if ($before_id) {
$cursor = $this->loadCursorObject($before_id);
} else {
$cursor = $this->loadCursorObject($after_id);
}
public function getOrderableColumns() {
$primary = ($this->buildingGlobalOrder ? null : 'r');
if (!$cursor) {
return null;
}
$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',
return array(
'id' => array(
'table' => $primary,
'column' => 'id',
'value' => $cursor->getID(),
'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() {
$is_global = $this->buildingGlobalOrder;
switch ($this->order) {
case self::ORDER_MODIFIED:
if ($is_global) {
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}'.");
}
protected function getPagingValueMap($cursor, array $keys) {
$revision = $this->loadCursorObject($cursor);
return array(
'id' => $revision->getID(),
'updated' => $revision->getDateModified(),
);
}
private function loadRelationships($conn_r, array $revisions) {