1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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
This commit is contained in:
epriestley 2017-05-26 09:43:40 -07:00
parent 69538274c1
commit 2d79229083
5 changed files with 37 additions and 39 deletions

View file

@ -67,16 +67,16 @@ final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod {
if (!$limit) {
$limit = $this->getDefaultLimit();
}
$filter_phids = $request->getValue('filterPHIDs');
if (!$filter_phids) {
$filter_phids = array();
}
$query = id(new PhabricatorFeedQuery())
->setLimit($limit)
->setFilterPHIDs($filter_phids)
->setViewer($user);
$filter_phids = $request->getValue('filterPHIDs');
if ($filter_phids) {
$query->withFilterPHIDs($filter_phids);
}
$after = $request->getValue('after');
if (strlen($after)) {
$query->setAfterID($after);

View file

@ -6,7 +6,7 @@ final class PhabricatorFeedQuery
private $filterPHIDs;
private $chronologicalKeys;
public function setFilterPHIDs(array $phids) {
public function withFilterPHIDs(array $phids) {
$this->filterPHIDs = $phids;
return $this;
}
@ -16,50 +16,46 @@ final class PhabricatorFeedQuery
return $this;
}
public function newResultObject() {
return new PhabricatorFeedStoryData();
}
protected function loadPage() {
$story_table = new PhabricatorFeedStoryData();
$conn = $story_table->establishConnection('r');
$data = queryfx_all(
$conn,
'SELECT story.* FROM %T story %Q %Q %Q %Q %Q',
$story_table->getTableName(),
$this->buildJoinClause($conn),
$this->buildWhereClause($conn),
$this->buildGroupClause($conn),
$this->buildOrderClause($conn),
$this->buildLimitClause($conn));
return $data;
// NOTE: We return raw rows from this method, which is a little unusual.
return $this->loadStandardPageRows($this->newResultObject());
}
protected function willFilterPage(array $data) {
return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer());
}
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
// NOTE: We perform this join unconditionally (even if we have no filter
// PHIDs) to omit rows which have no story references. These story data
// rows are notifications or realtime alerts.
$ref_table = new PhabricatorFeedStoryReference();
return qsprintf(
$conn_r,
$joins[] = qsprintf(
$conn,
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
$ref_table->getTableName());
return $joins;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->filterPHIDs) {
if ($this->filterPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'ref.objectPHID IN (%Ls)',
$this->filterPHIDs);
}
if ($this->chronologicalKeys) {
if ($this->chronologicalKeys !== null) {
// NOTE: We want to use integers in the query so we can take advantage
// of keys, but can't use %d on 32-bit systems. Make sure all the keys
// are integers and then format them raw.
@ -73,21 +69,19 @@ final class PhabricatorFeedQuery
}
$where[] = qsprintf(
$conn_r,
$conn,
'ref.chronologicalKey IN (%Q)',
implode(', ', $keys));
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
return $where;
}
protected function buildGroupClause(AphrontDatabaseConnection $conn_r) {
if ($this->filterPHIDs) {
return qsprintf($conn_r, 'GROUP BY ref.chronologicalKey');
protected function buildGroupClause(AphrontDatabaseConnection $conn) {
if ($this->filterPHIDs !== null) {
return qsprintf($conn, 'GROUP BY ref.chronologicalKey');
} else {
return qsprintf($conn_r, 'GROUP BY story.chronologicalKey');
return qsprintf($conn, 'GROUP BY story.chronologicalKey');
}
}
@ -120,6 +114,10 @@ final class PhabricatorFeedQuery
return $item['chronologicalKey'];
}
protected function getPrimaryTableAlias() {
return 'story';
}
public function getQueryApplicationClass() {
return 'PhabricatorFeedApplication';
}

View file

@ -56,7 +56,7 @@ final class PhabricatorFeedSearchEngine
$phids = array_mergev($phids);
if ($phids) {
$query->setFilterPHIDs($phids);
$query->withFilterPHIDs($phids);
}
return $query;

View file

@ -229,7 +229,7 @@ final class PhabricatorPeopleProfileViewController
$viewer) {
$query = new PhabricatorFeedQuery();
$query->setFilterPHIDs(
$query->withFilterPHIDs(
array(
$user->getPHID(),
));

View file

@ -73,7 +73,7 @@ final class PhabricatorProjectProfileController
$stories = id(new PhabricatorFeedQuery())
->setViewer($viewer)
->setFilterPHIDs(
->withFilterPHIDs(
array(
$project->getPHID(),
))