From 7b068d3e469048dd9f0d70878bd70892aac0e6bc Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 11 Aug 2012 07:05:45 -0700 Subject: [PATCH] Reverse project paging order Summary: Currently, we're showing projets in reverse order (Z..A) because most cursor pagers go from high IDs to low IDs. Allow sequence to be reversed; reverse it. Also simplify some query/paging stuff. Test Plan: Set page size to 1, paged back and forth. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D3221 --- .../PhabricatorProjectListController.php | 16 +++------------ .../project/query/PhabricatorProjectQuery.php | 4 ++++ .../PhabricatorCursorPagedPolicyQuery.php | 20 +++++++++++++------ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/applications/project/controller/PhabricatorProjectListController.php b/src/applications/project/controller/PhabricatorProjectListController.php index 139f3f7229..83f9cd3fa4 100644 --- a/src/applications/project/controller/PhabricatorProjectListController.php +++ b/src/applications/project/controller/PhabricatorProjectListController.php @@ -46,8 +46,7 @@ final class PhabricatorProjectListController $query = new PhabricatorProjectQuery(); $query->setViewer($request->getUser()); - $query->setOffset($pager->getOffset()); - $query->setLimit($pager->getPageSize() + 1); + $query->needMembers(true); $view_phid = $request->getUser()->getPHID(); @@ -69,8 +68,7 @@ final class PhabricatorProjectListController break; } - $projects = $query->execute(); - $projects = $pager->sliceResults($projects); + $projects = $query->executeWithOffsetPager($pager); $project_phids = mpull($projects, 'getPHID'); @@ -82,14 +80,6 @@ final class PhabricatorProjectListController $profiles = mpull($profiles, null, 'getProjectPHID'); } - $edge_query = new PhabricatorEdgeQuery(); - if ($projects) { - $edge_query - ->withSourcePHIDs($project_phids) - ->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)) - ->execute(); - } - $tasks = array(); $groups = array(); if ($project_phids) { @@ -112,7 +102,7 @@ final class PhabricatorProjectListController $phid = $project->getPHID(); $profile = idx($profiles, $phid); - $members = $edge_query->getDestinationPHIDs(array($phid)); + $members = $project->getMemberPHIDs(); $group = idx($groups, $phid, array()); $task_count = count($group); diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index f0187227b7..74fd7e5adc 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -64,6 +64,10 @@ final class PhabricatorProjectQuery extends PhabricatorCursorPagedPolicyQuery { return $result->getName(); } + protected function getReversePaging() { + return true; + } + public function loadPage() { $table = new PhabricatorProject(); $conn_r = $table->establishConnection('r'); diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyQuery.php index 8dda36f17d..a3059437ae 100644 --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyQuery.php @@ -34,6 +34,10 @@ abstract class PhabricatorCursorPagedPolicyQuery return $result->getID(); } + protected function getReversePaging() { + return false; + } + protected function nextPage(array $page) { if ($this->beforeID) { $this->beforeID = $this->getPagingValue(head($page)); @@ -66,14 +70,16 @@ abstract class PhabricatorCursorPagedPolicyQuery if ($this->beforeID) { return qsprintf( $conn_r, - '%Q > %s', + '%Q %Q %s', $this->getPagingColumn(), + $this->getReversePaging() ? '<' : '>', $this->beforeID); } else if ($this->afterID) { return qsprintf( $conn_r, - '%Q < %s', + '%Q %Q %s', $this->getPagingColumn(), + $this->getReversePaging() ? '>' : '<', $this->afterID); } @@ -84,13 +90,15 @@ abstract class PhabricatorCursorPagedPolicyQuery if ($this->beforeID) { return qsprintf( $conn_r, - 'ORDER BY %Q ASC', - $this->getPagingColumn()); + 'ORDER BY %Q %Q', + $this->getPagingColumn(), + $this->getReversePaging() ? 'DESC' : 'ASC'); } else { return qsprintf( $conn_r, - 'ORDER BY %Q DESC', - $this->getPagingColumn()); + 'ORDER BY %Q %Q', + $this->getPagingColumn(), + $this->getReversePaging() ? 'ASC' : 'DESC'); } }