From 511a8bae34ebf0a91b54877828f75065c570b705 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 4 Oct 2012 14:49:23 -0700 Subject: [PATCH] Optimize feed query Summary: This was killing us. `EXPLAIN` after:
idselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEstoryindexchronologicalKeychronologicalKey8201
1SIMPLErefrefchronologicalKeychronologicalKey8phabricator_feed.story.chronologicalKey1Using index
Test Plan: /feed/ Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3628 --- .../controller/PhabricatorDirectoryMainController.php | 1 + src/applications/feed/PhabricatorFeedQuery.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/applications/directory/controller/PhabricatorDirectoryMainController.php b/src/applications/directory/controller/PhabricatorDirectoryMainController.php index 43c29cbe99..76b8d5d198 100644 --- a/src/applications/directory/controller/PhabricatorDirectoryMainController.php +++ b/src/applications/directory/controller/PhabricatorDirectoryMainController.php @@ -139,6 +139,7 @@ final class PhabricatorDirectoryMainController $filter = $subnav->selectFilter($this->subfilter, 'all'); + $view = null; switch ($filter) { case 'all': $view = $this->buildFeedView(array()); diff --git a/src/applications/feed/PhabricatorFeedQuery.php b/src/applications/feed/PhabricatorFeedQuery.php index 25a58a8eda..2c954c8b49 100644 --- a/src/applications/feed/PhabricatorFeedQuery.php +++ b/src/applications/feed/PhabricatorFeedQuery.php @@ -76,11 +76,15 @@ final class PhabricatorFeedQuery private function buildGroupClause(AphrontDatabaseConnection $conn_r) { return qsprintf( $conn_r, - 'GROUP BY ref.chronologicalKey'); + 'GROUP BY '.($this->filterPHIDs + ? 'ref.chronologicalKey' + : 'story.chronologicalKey')); } protected function getPagingColumn() { - return 'ref.chronologicalKey'; + return ($this->filterPHIDs + ? 'ref.chronologicalKey' + : 'story.chronologicalKey'); } protected function getPagingValue($item) {