@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+77 -73
+2 -2
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 149 149 return $this->identifierMap; 150 150 } 151 151 152 - protected function getPagingColumn() { 153 - return 'commit.id'; 152 + protected function getPrimaryTableAlias() { 153 + return 'commit'; 154 154 } 155 155 156 156 protected function willExecute() {
+63 -61
src/applications/phrequent/query/PhrequentUserTimeQuery.php
··· 9 9 const ORDER_STARTED_DESC = 3; 10 10 const ORDER_ENDED_ASC = 4; 11 11 const ORDER_ENDED_DESC = 5; 12 - const ORDER_DURATION_ASC = 6; 13 - const ORDER_DURATION_DESC = 7; 14 12 15 13 const ENDED_YES = 0; 16 14 const ENDED_NO = 1; 17 15 const ENDED_ALL = 2; 18 16 17 + private $ids; 19 18 private $userPHIDs; 20 19 private $objectPHIDs; 21 - private $order = self::ORDER_ID_ASC; 22 20 private $ended = self::ENDED_ALL; 23 21 24 22 private $needPreemptingEvents; 25 23 26 - public function withUserPHIDs($user_phids) { 24 + public function withIDs(array $ids) { 25 + $this->ids = $ids; 26 + return $this; 27 + } 28 + 29 + public function withUserPHIDs(array $user_phids) { 27 30 $this->userPHIDs = $user_phids; 28 31 return $this; 29 32 } 30 33 31 - public function withObjectPHIDs($object_phids) { 34 + public function withObjectPHIDs(array $object_phids) { 32 35 $this->objectPHIDs = $object_phids; 33 36 return $this; 34 37 } ··· 39 42 } 40 43 41 44 public function setOrder($order) { 42 - $this->order = $order; 45 + switch ($order) { 46 + case self::ORDER_ID_ASC: 47 + $this->setOrderVector(array('-id')); 48 + break; 49 + case self::ORDER_ID_DESC: 50 + $this->setOrderVector(array('id')); 51 + break; 52 + case self::ORDER_STARTED_ASC: 53 + $this->setOrderVector(array('-start', '-id')); 54 + break; 55 + case self::ORDER_STARTED_DESC: 56 + $this->setOrderVector(array('start', 'id')); 57 + break; 58 + case self::ORDER_ENDED_ASC: 59 + $this->setOrderVector(array('-ongoing', '-end', '-id')); 60 + break; 61 + case self::ORDER_ENDED_DESC: 62 + $this->setOrderVector(array('ongoing', 'end', 'id')); 63 + break; 64 + default: 65 + throw new Exception(pht('Unknown order "%s".', $order)); 66 + } 67 + 43 68 return $this; 44 69 } 45 70 ··· 51 76 private function buildWhereClause(AphrontDatabaseConnection $conn) { 52 77 $where = array(); 53 78 54 - if ($this->userPHIDs) { 79 + if ($this->ids !== null) { 80 + $where[] = qsprintf( 81 + $conn, 82 + 'id IN (%Ld)', 83 + $this->ids); 84 + } 85 + 86 + if ($this->userPHIDs !== null) { 55 87 $where[] = qsprintf( 56 88 $conn, 57 89 'userPHID IN (%Ls)', 58 90 $this->userPHIDs); 59 91 } 60 92 61 - if ($this->objectPHIDs) { 93 + if ($this->objectPHIDs !== null) { 62 94 $where[] = qsprintf( 63 95 $conn, 64 96 'objectPHID IN (%Ls)', ··· 87 119 return $this->formatWhereClause($where); 88 120 } 89 121 90 - protected function getPagingColumn() { 91 - switch ($this->order) { 92 - case self::ORDER_ID_ASC: 93 - case self::ORDER_ID_DESC: 94 - return 'id'; 95 - case self::ORDER_STARTED_ASC: 96 - case self::ORDER_STARTED_DESC: 97 - return 'dateStarted'; 98 - case self::ORDER_ENDED_ASC: 99 - case self::ORDER_ENDED_DESC: 100 - return 'dateEnded'; 101 - case self::ORDER_DURATION_ASC: 102 - case self::ORDER_DURATION_DESC: 103 - return 'COALESCE(dateEnded, UNIX_TIMESTAMP()) - dateStarted'; 104 - default: 105 - throw new Exception("Unknown order '{$this->order}'!"); 106 - } 107 - } 108 - 109 - protected function getPagingValue($result) { 110 - switch ($this->order) { 111 - case self::ORDER_ID_ASC: 112 - case self::ORDER_ID_DESC: 113 - return $result->getID(); 114 - case self::ORDER_STARTED_ASC: 115 - case self::ORDER_STARTED_DESC: 116 - return $result->getDateStarted(); 117 - case self::ORDER_ENDED_ASC: 118 - case self::ORDER_ENDED_DESC: 119 - return $result->getDateEnded(); 120 - case self::ORDER_DURATION_ASC: 121 - case self::ORDER_DURATION_DESC: 122 - return ($result->getDateEnded() || time()) - $result->getDateStarted(); 123 - default: 124 - throw new Exception("Unknown order '{$this->order}'!"); 125 - } 122 + public function getOrderableColumns() { 123 + return parent::getOrderableColumns() + array( 124 + 'start' => array( 125 + 'column' => 'dateStarted', 126 + 'type' => 'int', 127 + ), 128 + 'ongoing' => array( 129 + 'column' => 'dateEnded', 130 + 'type' => 'null', 131 + ), 132 + 'end' => array( 133 + 'column' => 'dateEnded', 134 + 'type' => 'int', 135 + ), 136 + ); 126 137 } 127 138 128 - protected function getReversePaging() { 129 - switch ($this->order) { 130 - case self::ORDER_ID_ASC: 131 - case self::ORDER_STARTED_ASC: 132 - case self::ORDER_ENDED_ASC: 133 - case self::ORDER_DURATION_ASC: 134 - return true; 135 - case self::ORDER_ID_DESC: 136 - case self::ORDER_STARTED_DESC: 137 - case self::ORDER_ENDED_DESC: 138 - case self::ORDER_DURATION_DESC: 139 - return false; 140 - default: 141 - throw new Exception("Unknown order '{$this->order}'!"); 142 - } 139 + protected function getPagingValueMap($cursor, array $keys) { 140 + $usertime = $this->loadCursorObject($cursor); 141 + return array( 142 + 'id' => $usertime->getID(), 143 + 'start' => $usertime->getDateStarted(), 144 + 'ongoing' => $usertime->getDateEnded(), 145 + 'end' => $usertime->getDateEnded(), 146 + ); 143 147 } 144 148 145 149 protected function loadPage() { ··· 249 253 self::ORDER_STARTED_DESC => pht('by nearest start date'), 250 254 self::ORDER_ENDED_ASC => pht('by furthest end date'), 251 255 self::ORDER_ENDED_DESC => pht('by nearest end date'), 252 - self::ORDER_DURATION_ASC => pht('by smallest duration'), 253 - self::ORDER_DURATION_DESC => pht('by largest duration'), 254 256 ); 255 257 } 256 258
+12 -10
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 570 570 $table = idx($part, 'table'); 571 571 $column = $part['column']; 572 572 573 + if ($table !== null) { 574 + $field = qsprintf($conn, '%T.%T', $table, $column); 575 + } else { 576 + $field = qsprintf($conn, '%T', $column); 577 + } 578 + 579 + if (idx($part, 'type') === 'null') { 580 + $field = qsprintf($conn, '(%Q IS NULL)', $field); 581 + } 582 + 573 583 if ($descending) { 574 - if ($table !== null) { 575 - $sql[] = qsprintf($conn, '%T.%T DESC', $table, $column); 576 - } else { 577 - $sql[] = qsprintf($conn, '%T DESC', $column); 578 - } 584 + $sql[] = qsprintf($conn, '%Q DESC', $field); 579 585 } else { 580 - if ($table !== null) { 581 - $sql[] = qsprintf($conn, '%T.%T ASC', $table, $column); 582 - } else { 583 - $sql[] = qsprintf($conn, '%T ASC', $column); 584 - } 586 + $sql[] = qsprintf($conn, '%Q ASC', $field); 585 587 } 586 588 } 587 589