@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 FeedQuery a little bit

Summary: Ref T12762. Updates some conventions and methods. This has no (meaningful) behavioral changes.

Test Plan:
- Grepped for `setFilterPHIDs()`.
- Viewed main feed, user feed, project feed.
- Called `feed.query`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12762

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

+37 -39
+5 -5
src/applications/feed/conduit/FeedQueryConduitAPIMethod.php
··· 67 67 if (!$limit) { 68 68 $limit = $this->getDefaultLimit(); 69 69 } 70 - $filter_phids = $request->getValue('filterPHIDs'); 71 - if (!$filter_phids) { 72 - $filter_phids = array(); 73 - } 74 70 75 71 $query = id(new PhabricatorFeedQuery()) 76 72 ->setLimit($limit) 77 - ->setFilterPHIDs($filter_phids) 78 73 ->setViewer($user); 74 + 75 + $filter_phids = $request->getValue('filterPHIDs'); 76 + if ($filter_phids) { 77 + $query->withFilterPHIDs($filter_phids); 78 + } 79 79 80 80 $after = $request->getValue('after'); 81 81 if (strlen($after)) {
+29 -31
src/applications/feed/query/PhabricatorFeedQuery.php
··· 6 6 private $filterPHIDs; 7 7 private $chronologicalKeys; 8 8 9 - public function setFilterPHIDs(array $phids) { 9 + public function withFilterPHIDs(array $phids) { 10 10 $this->filterPHIDs = $phids; 11 11 return $this; 12 12 } ··· 16 16 return $this; 17 17 } 18 18 19 - protected function loadPage() { 20 - $story_table = new PhabricatorFeedStoryData(); 21 - $conn = $story_table->establishConnection('r'); 22 - 23 - $data = queryfx_all( 24 - $conn, 25 - 'SELECT story.* FROM %T story %Q %Q %Q %Q %Q', 26 - $story_table->getTableName(), 27 - $this->buildJoinClause($conn), 28 - $this->buildWhereClause($conn), 29 - $this->buildGroupClause($conn), 30 - $this->buildOrderClause($conn), 31 - $this->buildLimitClause($conn)); 19 + public function newResultObject() { 20 + return new PhabricatorFeedStoryData(); 21 + } 32 22 33 - return $data; 23 + protected function loadPage() { 24 + // NOTE: We return raw rows from this method, which is a little unusual. 25 + return $this->loadStandardPageRows($this->newResultObject()); 34 26 } 35 27 36 28 protected function willFilterPage(array $data) { 37 29 return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer()); 38 30 } 39 31 40 - protected function buildJoinClause(AphrontDatabaseConnection $conn_r) { 32 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 33 + $joins = parent::buildJoinClauseParts($conn); 34 + 41 35 // NOTE: We perform this join unconditionally (even if we have no filter 42 36 // PHIDs) to omit rows which have no story references. These story data 43 37 // rows are notifications or realtime alerts. 44 38 45 39 $ref_table = new PhabricatorFeedStoryReference(); 46 - return qsprintf( 47 - $conn_r, 40 + $joins[] = qsprintf( 41 + $conn, 48 42 'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey', 49 43 $ref_table->getTableName()); 44 + 45 + return $joins; 50 46 } 51 47 52 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 53 - $where = array(); 48 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 49 + $where = parent::buildWhereClauseParts($conn); 54 50 55 - if ($this->filterPHIDs) { 51 + if ($this->filterPHIDs !== null) { 56 52 $where[] = qsprintf( 57 - $conn_r, 53 + $conn, 58 54 'ref.objectPHID IN (%Ls)', 59 55 $this->filterPHIDs); 60 56 } 61 57 62 - if ($this->chronologicalKeys) { 58 + if ($this->chronologicalKeys !== null) { 63 59 // NOTE: We want to use integers in the query so we can take advantage 64 60 // of keys, but can't use %d on 32-bit systems. Make sure all the keys 65 61 // are integers and then format them raw. ··· 73 69 } 74 70 75 71 $where[] = qsprintf( 76 - $conn_r, 72 + $conn, 77 73 'ref.chronologicalKey IN (%Q)', 78 74 implode(', ', $keys)); 79 75 } 80 76 81 - $where[] = $this->buildPagingClause($conn_r); 82 - 83 - return $this->formatWhereClause($where); 77 + return $where; 84 78 } 85 79 86 - protected function buildGroupClause(AphrontDatabaseConnection $conn_r) { 87 - if ($this->filterPHIDs) { 88 - return qsprintf($conn_r, 'GROUP BY ref.chronologicalKey'); 80 + protected function buildGroupClause(AphrontDatabaseConnection $conn) { 81 + if ($this->filterPHIDs !== null) { 82 + return qsprintf($conn, 'GROUP BY ref.chronologicalKey'); 89 83 } else { 90 - return qsprintf($conn_r, 'GROUP BY story.chronologicalKey'); 84 + return qsprintf($conn, 'GROUP BY story.chronologicalKey'); 91 85 } 92 86 } 93 87 ··· 118 112 return $item->getChronologicalKey(); 119 113 } 120 114 return $item['chronologicalKey']; 115 + } 116 + 117 + protected function getPrimaryTableAlias() { 118 + return 'story'; 121 119 } 122 120 123 121 public function getQueryApplicationClass() {
+1 -1
src/applications/feed/query/PhabricatorFeedSearchEngine.php
··· 56 56 57 57 $phids = array_mergev($phids); 58 58 if ($phids) { 59 - $query->setFilterPHIDs($phids); 59 + $query->withFilterPHIDs($phids); 60 60 } 61 61 62 62 return $query;
+1 -1
src/applications/people/controller/PhabricatorPeopleProfileViewController.php
··· 229 229 $viewer) { 230 230 231 231 $query = new PhabricatorFeedQuery(); 232 - $query->setFilterPHIDs( 232 + $query->withFilterPHIDs( 233 233 array( 234 234 $user->getPHID(), 235 235 ));
+1 -1
src/applications/project/controller/PhabricatorProjectProfileController.php
··· 73 73 74 74 $stories = id(new PhabricatorFeedQuery()) 75 75 ->setViewer($viewer) 76 - ->setFilterPHIDs( 76 + ->withFilterPHIDs( 77 77 array( 78 78 $project->getPHID(), 79 79 ))