@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 ReleephProjectQuery ordering/paging

Summary: Ref T7803. Continue removing implementations of getPagingColumn() and getReversePaging().

Test Plan: Browsed and paged through Releeph projects, Maniphest tasks, Diffusion repositories.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7803

Differential Revision: https://secure.phabricator.com/D12358

+42 -41
-8
src/applications/differential/query/DifferentialRevisionQuery.php
··· 861 861 } 862 862 } 863 863 864 - private function loadCursorObject($id) { 865 - $results = id(new DifferentialRevisionQuery()) 866 - ->setViewer($this->getPagingViewer()) 867 - ->withIDs(array((int)$id)) 868 - ->execute(); 869 - return head($results); 870 - } 871 - 872 864 protected function buildPagingClause(AphrontDatabaseConnection $conn_r) { 873 865 $default = parent::buildPagingClause($conn_r); 874 866
-8
src/applications/maniphest/query/ManiphestTaskQuery.php
··· 949 949 return array_mergev($phids); 950 950 } 951 951 952 - private function loadCursorObject($id) { 953 - $results = id(new ManiphestTaskQuery()) 954 - ->setViewer($this->getPagingViewer()) 955 - ->withIDs(array((int)$id)) 956 - ->execute(); 957 - return head($results); 958 - } 959 - 960 952 protected function getPagingValue($result) { 961 953 $id = $result->getID(); 962 954
+25 -24
src/applications/releeph/query/ReleephProductQuery.php
··· 10 10 11 11 private $needArcanistProjects; 12 12 13 - private $order = 'order-id'; 14 13 const ORDER_ID = 'order-id'; 15 14 const ORDER_NAME = 'order-name'; 16 15 ··· 20 19 } 21 20 22 21 public function setOrder($order) { 23 - $this->order = $order; 22 + switch ($order) { 23 + case self::ORDER_ID: 24 + $this->setOrderVector(array('id')); 25 + break; 26 + case self::ORDER_NAME: 27 + $this->setOrderVector(array('name')); 28 + break; 29 + default: 30 + throw new Exception(pht('Order "%s" not supported.', $order)); 31 + } 24 32 return $this; 25 33 } 26 34 ··· 139 147 return $this->formatWhereClause($where); 140 148 } 141 149 142 - protected function getReversePaging() { 143 - switch ($this->order) { 144 - case self::ORDER_NAME: 145 - return true; 146 - } 147 - return parent::getReversePaging(); 150 + public function getOrderableColumns() { 151 + return parent::getOrderableColumns() + array( 152 + 'name' => array( 153 + 'column' => 'name', 154 + 'unique' => true, 155 + 'reverse' => true, 156 + 'type' => 'string', 157 + ), 158 + ); 148 159 } 149 160 150 - protected function getPagingValue($result) { 151 - switch ($this->order) { 152 - case self::ORDER_NAME: 153 - return $result->getName(); 154 - } 155 - return parent::getPagingValue(); 156 - } 161 + protected function getPagingValueMap($cursor, array $keys) { 162 + $product = $this->loadCursorObject($cursor); 157 163 158 - protected function getPagingColumn() { 159 - switch ($this->order) { 160 - case self::ORDER_NAME: 161 - return 'name'; 162 - case self::ORDER_ID: 163 - return parent::getPagingColumn(); 164 - default: 165 - throw new Exception("Uknown order '{$this->order}'!"); 166 - } 164 + return array( 165 + 'id' => $product->getID(), 166 + 'name' => $product->getName(), 167 + ); 167 168 } 168 169 169 170 public function getQueryApplicationClass() {
+1 -1
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 340 340 return $this->formatOrderClause($conn, $parts); 341 341 } 342 342 343 - private function loadCursorObject($id) { 343 + protected function loadCursorObject($id) { 344 344 $query = id(new PhabricatorRepositoryQuery()) 345 345 ->setViewer($this->getPagingViewer()) 346 346 ->withIDs(array((int)$id));
+16
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 244 244 ); 245 245 } 246 246 247 + protected function loadCursorObject($cursor) { 248 + $query = newv(get_class($this), array()) 249 + ->setViewer($this->getPagingViewer()) 250 + ->withIDs(array((int)$cursor)); 251 + 252 + $object = $query->executeOne(); 253 + if (!$object) { 254 + throw new Exception( 255 + pht( 256 + 'Cursor "%s" does not identify a valid object.', 257 + $cursor)); 258 + } 259 + 260 + return $object; 261 + } 262 + 247 263 248 264 /** 249 265 * Simplifies the task of constructing a paging clause across multiple