diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php index 45359cac1a..13399bd7cc 100644 --- a/src/applications/differential/query/DifferentialRevisionQuery.php +++ b/src/applications/differential/query/DifferentialRevisionQuery.php @@ -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; - } - - if ($before_id) { - $cursor = $this->loadCursorObject($before_id); - } else { - $cursor = $this->loadCursorObject($after_id); - } - - 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', - 'column' => 'id', - 'value' => $cursor->getID(), - 'type' => 'int', - ); - - return $this->buildPagingClauseFromMultipleColumns( - $conn_r, - $columns, - array( - 'reversed' => (bool)($before_id xor $this->getReversePaging()), - )); + protected function getDefaultOrderVector() { + return array('updated', 'id'); } - 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}'."); - } + public function getOrderableColumns() { + $primary = ($this->buildingGlobalOrder ? null : 'r'); + + return array( + 'id' => array( + 'table' => $primary, + 'column' => 'id', + 'type' => 'int', + 'unique' => true, + ), + 'updated' => array( + 'table' => $primary, + 'column' => 'dateModified', + 'type' => 'int', + ), + ); + } + + 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) {