Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15469523
D12363.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D12363.diff
View Options
diff --git a/src/applications/diffusion/query/DiffusionCommitQuery.php b/src/applications/diffusion/query/DiffusionCommitQuery.php
--- a/src/applications/diffusion/query/DiffusionCommitQuery.php
+++ b/src/applications/diffusion/query/DiffusionCommitQuery.php
@@ -149,8 +149,8 @@
return $this->identifierMap;
}
- protected function getPagingColumn() {
- return 'commit.id';
+ protected function getPrimaryTableAlias() {
+ return 'commit';
}
protected function willExecute() {
diff --git a/src/applications/phrequent/query/PhrequentUserTimeQuery.php b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
--- a/src/applications/phrequent/query/PhrequentUserTimeQuery.php
+++ b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
@@ -9,26 +9,29 @@
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 @@
}
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 @@
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 @@
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}'!");
- }
- }
-
- 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}'!");
- }
+ 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 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 @@
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'),
);
}
diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
--- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
+++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
@@ -570,18 +570,20 @@
$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);
- } else {
- $sql[] = qsprintf($conn, '%T DESC', $column);
- }
+ $sql[] = qsprintf($conn, '%Q DESC', $field);
} 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);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 5, 2:09 PM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7314892
Default Alt Text
D12363.diff (7 KB)
Attached To
Mode
D12363: Modernize Phrequent and Commit query ordering/paging
Attached
Detach File
Event Timeline
Log In to Comment