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

Summary: Ref T7803. Fixes T7809. Move Phriction away from getReversePaging() / getPagingColumn().

Test Plan: Paged "All Documents", "Updated", and viewed document hierarchy.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: ite-klass, epriestley

Maniphest Tasks: T7809, T7803

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

+77 -47
+63 -44
src/applications/phriction/query/PhrictionDocumentQuery.php
··· 17 17 const STATUS_OPEN = 'status-open'; 18 18 const STATUS_NONSTUB = 'status-nonstub'; 19 19 20 - private $order = 'order-created'; 21 20 const ORDER_CREATED = 'order-created'; 22 21 const ORDER_UPDATED = 'order-updated'; 23 22 const ORDER_HIERARCHY = 'order-hierarchy'; ··· 63 62 } 64 63 65 64 public function setOrder($order) { 66 - $this->order = $order; 65 + switch ($order) { 66 + case self::ORDER_CREATED: 67 + $this->setOrderVector(array('id')); 68 + break; 69 + case self::ORDER_UPDATED: 70 + $this->setOrderVector(array('updated')); 71 + break; 72 + case self::ORDER_HIERARCHY: 73 + $this->setOrderVector(array('depth', 'title', 'updated')); 74 + break; 75 + default: 76 + throw new Exception(pht('Unknown order "%s".', $order)); 77 + } 78 + 67 79 return $this; 68 80 } 69 81 ··· 71 83 $table = new PhrictionDocument(); 72 84 $conn_r = $table->establishConnection('r'); 73 85 74 - if ($this->order == self::ORDER_HIERARCHY) { 75 - $order_clause = $this->buildHierarchicalOrderClause($conn_r); 76 - } else { 77 - $order_clause = $this->buildOrderClause($conn_r); 78 - } 79 - 80 86 $rows = queryfx_all( 81 87 $conn_r, 82 88 'SELECT d.* FROM %T d %Q %Q %Q %Q', 83 89 $table->getTableName(), 84 90 $this->buildJoinClause($conn_r), 85 91 $this->buildWhereClause($conn_r), 86 - $order_clause, 92 + $this->buildOrderClause($conn_r), 87 93 $this->buildLimitClause($conn_r)); 88 94 89 95 $documents = $table->loadAllFromArray($rows); ··· 186 192 187 193 private function buildJoinClause(AphrontDatabaseConnection $conn) { 188 194 $join = ''; 189 - if ($this->order == self::ORDER_HIERARCHY) { 195 + 196 + if ($this->getOrderVector()->containsKey('updated')) { 190 197 $content_dao = new PhrictionContent(); 191 198 $join = qsprintf( 192 199 $conn, 193 200 'JOIN %T c ON d.contentID = c.id', 194 201 $content_dao->getTableName()); 195 202 } 203 + 196 204 return $join; 197 205 } 198 206 protected function buildWhereClause(AphrontDatabaseConnection $conn) { ··· 271 279 return $this->formatWhereClause($where); 272 280 } 273 281 274 - private function buildHierarchicalOrderClause( 275 - AphrontDatabaseConnection $conn_r) { 282 + public function getOrderableColumns() { 283 + return parent::getOrderableColumns() + array( 284 + 'depth' => array( 285 + 'table' => 'd', 286 + 'column' => 'depth', 287 + 'reverse' => true, 288 + 'type' => 'int', 289 + ), 290 + 'title' => array( 291 + 'table' => 'c', 292 + 'column' => 'title', 293 + 'reverse' => true, 294 + 'type' => 'string', 295 + ), 296 + 'updated' => array( 297 + 'table' => 'd', 298 + 'column' => 'contentID', 299 + 'type' => 'int', 300 + 'unique' => true, 301 + ), 302 + ); 303 + } 304 + 305 + protected function getPagingValueMap($cursor, array $keys) { 306 + $document = $this->loadCursorObject($cursor); 307 + 308 + $map = array( 309 + 'id' => $document->getID(), 310 + 'depth' => $document->getDepth(), 311 + 'updated' => $document->getContentID(), 312 + ); 276 313 277 - if ($this->getBeforeID()) { 278 - return qsprintf( 279 - $conn_r, 280 - 'ORDER BY d.depth, c.title, %Q %Q', 281 - $this->getPagingColumn(), 282 - $this->getReversePaging() ? 'DESC' : 'ASC'); 283 - } else { 284 - return qsprintf( 285 - $conn_r, 286 - 'ORDER BY d.depth, c.title, %Q %Q', 287 - $this->getPagingColumn(), 288 - $this->getReversePaging() ? 'ASC' : 'DESC'); 314 + foreach ($keys as $key) { 315 + switch ($key) { 316 + case 'title': 317 + $map[$key] = $document->getContent()->getTitle(); 318 + break; 319 + } 289 320 } 321 + 322 + return $map; 290 323 } 291 324 292 - protected function getPagingColumn() { 293 - switch ($this->order) { 294 - case self::ORDER_CREATED: 295 - case self::ORDER_HIERARCHY: 296 - return 'd.id'; 297 - case self::ORDER_UPDATED: 298 - return 'd.contentID'; 299 - default: 300 - throw new Exception("Unknown order '{$this->order}'!"); 301 - } 302 - } 325 + protected function willExecuteCursorQuery( 326 + PhabricatorCursorPagedPolicyAwareQuery $query) { 327 + $vector = $this->getOrderVector(); 303 328 304 - protected function getPagingValue($result) { 305 - switch ($this->order) { 306 - case self::ORDER_CREATED: 307 - case self::ORDER_HIERARCHY: 308 - return $result->getID(); 309 - case self::ORDER_UPDATED: 310 - return $result->getContentID(); 311 - default: 312 - throw new Exception("Unknown order '{$this->order}'!"); 329 + if ($vector->containsKey('title')) { 330 + $query->needContent(true); 313 331 } 314 332 } 333 + 315 334 316 335 public function getQueryApplicationClass() { 317 336 return 'PhabricatorPhrictionApplication';
+2 -2
src/applications/phriction/query/PhrictionSearchEngine.php
··· 14 14 public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 15 $saved = new PhabricatorSavedQuery(); 16 16 17 - $saved->setParameter('status', $request->getArr('status')); 18 - $saved->setParameter('order', $request->getArr('order')); 17 + $saved->setParameter('status', $request->getStr('status')); 18 + $saved->setParameter('order', $request->getStr('order')); 19 19 20 20 return $saved; 21 21 }
+4
src/infrastructure/query/order/PhabricatorQueryOrderVector.php
··· 92 92 return implode(', ', $scalars); 93 93 } 94 94 95 + public function containsKey($key) { 96 + return isset($this->items[$key]); 97 + } 98 + 95 99 96 100 /* -( Iterator Interface )------------------------------------------------- */ 97 101
+8 -1
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 249 249 ->setViewer($this->getPagingViewer()) 250 250 ->withIDs(array((int)$cursor)); 251 251 252 + $this->willExecuteCursorQuery($query); 253 + 252 254 $object = $query->executeOne(); 253 255 if (!$object) { 254 256 throw new Exception( ··· 258 260 } 259 261 260 262 return $object; 263 + } 264 + 265 + protected function willExecuteCursorQuery( 266 + PhabricatorCursorPagedPolicyAwareQuery $query) { 267 + return; 261 268 } 262 269 263 270 ··· 446 453 /** 447 454 * @task order 448 455 */ 449 - private function getOrderVector() { 456 + protected function getOrderVector() { 450 457 if (!$this->orderVector) { 451 458 $vector = $this->getDefaultOrderVector(); 452 459 $vector = PhabricatorQueryOrderVector::newFromVector($vector);