mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
Modernize Phrequent and Commit query ordering/paging
Summary: Ref T7803. Fixes T3870. Move these away from pagingColumn / reversePaging. Test Plan: - Tested/paged audit query. - Poked at Phrequent. Didn't seem any more broken than before. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3870, T7803 Differential Revision: https://secure.phabricator.com/D12363
This commit is contained in:
parent
51dabc5007
commit
9c7c13ffc8
3 changed files with 78 additions and 74 deletions
|
@ -149,8 +149,8 @@ final class DiffusionCommitQuery
|
|||
return $this->identifierMap;
|
||||
}
|
||||
|
||||
protected function getPagingColumn() {
|
||||
return 'commit.id';
|
||||
protected function getPrimaryTableAlias() {
|
||||
return 'commit';
|
||||
}
|
||||
|
||||
protected function willExecute() {
|
||||
|
|
|
@ -9,26 +9,29 @@ final class PhrequentUserTimeQuery
|
|||
const ORDER_STARTED_DESC = 3;
|
||||
const ORDER_ENDED_ASC = 4;
|
||||
const ORDER_ENDED_DESC = 5;
|
||||
const ORDER_DURATION_ASC = 6;
|
||||
const ORDER_DURATION_DESC = 7;
|
||||
|
||||
const ENDED_YES = 0;
|
||||
const ENDED_NO = 1;
|
||||
const ENDED_ALL = 2;
|
||||
|
||||
private $ids;
|
||||
private $userPHIDs;
|
||||
private $objectPHIDs;
|
||||
private $order = self::ORDER_ID_ASC;
|
||||
private $ended = self::ENDED_ALL;
|
||||
|
||||
private $needPreemptingEvents;
|
||||
|
||||
public function withUserPHIDs($user_phids) {
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withUserPHIDs(array $user_phids) {
|
||||
$this->userPHIDs = $user_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withObjectPHIDs($object_phids) {
|
||||
public function withObjectPHIDs(array $object_phids) {
|
||||
$this->objectPHIDs = $object_phids;
|
||||
return $this;
|
||||
}
|
||||
|
@ -39,7 +42,29 @@ final class PhrequentUserTimeQuery
|
|||
}
|
||||
|
||||
public function setOrder($order) {
|
||||
$this->order = $order;
|
||||
switch ($order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
$this->setOrderVector(array('-id'));
|
||||
break;
|
||||
case self::ORDER_ID_DESC:
|
||||
$this->setOrderVector(array('id'));
|
||||
break;
|
||||
case self::ORDER_STARTED_ASC:
|
||||
$this->setOrderVector(array('-start', '-id'));
|
||||
break;
|
||||
case self::ORDER_STARTED_DESC:
|
||||
$this->setOrderVector(array('start', 'id'));
|
||||
break;
|
||||
case self::ORDER_ENDED_ASC:
|
||||
$this->setOrderVector(array('-ongoing', '-end', '-id'));
|
||||
break;
|
||||
case self::ORDER_ENDED_DESC:
|
||||
$this->setOrderVector(array('ongoing', 'end', 'id'));
|
||||
break;
|
||||
default:
|
||||
throw new Exception(pht('Unknown order "%s".', $order));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -51,14 +76,21 @@ final class PhrequentUserTimeQuery
|
|||
private function buildWhereClause(AphrontDatabaseConnection $conn) {
|
||||
$where = array();
|
||||
|
||||
if ($this->userPHIDs) {
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->userPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'userPHID IN (%Ls)',
|
||||
$this->userPHIDs);
|
||||
}
|
||||
|
||||
if ($this->objectPHIDs) {
|
||||
if ($this->objectPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'objectPHID IN (%Ls)',
|
||||
|
@ -87,59 +119,31 @@ final class PhrequentUserTimeQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
protected function getPagingColumn() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_ID_DESC:
|
||||
return 'id';
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
return 'dateStarted';
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
return 'dateEnded';
|
||||
case self::ORDER_DURATION_ASC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return 'COALESCE(dateEnded, UNIX_TIMESTAMP()) - dateStarted';
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
public function getOrderableColumns() {
|
||||
return parent::getOrderableColumns() + array(
|
||||
'start' => array(
|
||||
'column' => 'dateStarted',
|
||||
'type' => 'int',
|
||||
),
|
||||
'ongoing' => array(
|
||||
'column' => 'dateEnded',
|
||||
'type' => 'null',
|
||||
),
|
||||
'end' => array(
|
||||
'column' => 'dateEnded',
|
||||
'type' => 'int',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getPagingValue($result) {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_ID_DESC:
|
||||
return $result->getID();
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
return $result->getDateStarted();
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
return $result->getDateEnded();
|
||||
case self::ORDER_DURATION_ASC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return ($result->getDateEnded() || time()) - $result->getDateStarted();
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getReversePaging() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_DURATION_ASC:
|
||||
return true;
|
||||
case self::ORDER_ID_DESC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return false;
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
protected function getPagingValueMap($cursor, array $keys) {
|
||||
$usertime = $this->loadCursorObject($cursor);
|
||||
return array(
|
||||
'id' => $usertime->getID(),
|
||||
'start' => $usertime->getDateStarted(),
|
||||
'ongoing' => $usertime->getDateEnded(),
|
||||
'end' => $usertime->getDateEnded(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
|
@ -249,8 +253,6 @@ final class PhrequentUserTimeQuery
|
|||
self::ORDER_STARTED_DESC => pht('by nearest start date'),
|
||||
self::ORDER_ENDED_ASC => pht('by furthest end date'),
|
||||
self::ORDER_ENDED_DESC => pht('by nearest end date'),
|
||||
self::ORDER_DURATION_ASC => pht('by smallest duration'),
|
||||
self::ORDER_DURATION_DESC => pht('by largest duration'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -570,18 +570,20 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
|||
$table = idx($part, 'table');
|
||||
$column = $part['column'];
|
||||
|
||||
if ($table !== null) {
|
||||
$field = qsprintf($conn, '%T.%T', $table, $column);
|
||||
} else {
|
||||
$field = qsprintf($conn, '%T', $column);
|
||||
}
|
||||
|
||||
if (idx($part, 'type') === 'null') {
|
||||
$field = qsprintf($conn, '(%Q IS NULL)', $field);
|
||||
}
|
||||
|
||||
if ($descending) {
|
||||
if ($table !== null) {
|
||||
$sql[] = qsprintf($conn, '%T.%T DESC', $table, $column);
|
||||
$sql[] = qsprintf($conn, '%Q DESC', $field);
|
||||
} else {
|
||||
$sql[] = qsprintf($conn, '%T DESC', $column);
|
||||
}
|
||||
} else {
|
||||
if ($table !== null) {
|
||||
$sql[] = qsprintf($conn, '%T.%T ASC', $table, $column);
|
||||
} else {
|
||||
$sql[] = qsprintf($conn, '%T ASC', $column);
|
||||
}
|
||||
$sql[] = qsprintf($conn, '%Q ASC', $field);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue