mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01: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:
parent
69538274c1
commit
2d79229083
5 changed files with 37 additions and 39 deletions
|
@ -67,16 +67,16 @@ final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod {
|
||||||
if (!$limit) {
|
if (!$limit) {
|
||||||
$limit = $this->getDefaultLimit();
|
$limit = $this->getDefaultLimit();
|
||||||
}
|
}
|
||||||
$filter_phids = $request->getValue('filterPHIDs');
|
|
||||||
if (!$filter_phids) {
|
|
||||||
$filter_phids = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = id(new PhabricatorFeedQuery())
|
$query = id(new PhabricatorFeedQuery())
|
||||||
->setLimit($limit)
|
->setLimit($limit)
|
||||||
->setFilterPHIDs($filter_phids)
|
|
||||||
->setViewer($user);
|
->setViewer($user);
|
||||||
|
|
||||||
|
$filter_phids = $request->getValue('filterPHIDs');
|
||||||
|
if ($filter_phids) {
|
||||||
|
$query->withFilterPHIDs($filter_phids);
|
||||||
|
}
|
||||||
|
|
||||||
$after = $request->getValue('after');
|
$after = $request->getValue('after');
|
||||||
if (strlen($after)) {
|
if (strlen($after)) {
|
||||||
$query->setAfterID($after);
|
$query->setAfterID($after);
|
||||||
|
|
|
@ -6,7 +6,7 @@ final class PhabricatorFeedQuery
|
||||||
private $filterPHIDs;
|
private $filterPHIDs;
|
||||||
private $chronologicalKeys;
|
private $chronologicalKeys;
|
||||||
|
|
||||||
public function setFilterPHIDs(array $phids) {
|
public function withFilterPHIDs(array $phids) {
|
||||||
$this->filterPHIDs = $phids;
|
$this->filterPHIDs = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -16,50 +16,46 @@ final class PhabricatorFeedQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newResultObject() {
|
||||||
|
return new PhabricatorFeedStoryData();
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$story_table = new PhabricatorFeedStoryData();
|
// NOTE: We return raw rows from this method, which is a little unusual.
|
||||||
$conn = $story_table->establishConnection('r');
|
return $this->loadStandardPageRows($this->newResultObject());
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willFilterPage(array $data) {
|
protected function willFilterPage(array $data) {
|
||||||
return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer());
|
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
|
// NOTE: We perform this join unconditionally (even if we have no filter
|
||||||
// PHIDs) to omit rows which have no story references. These story data
|
// PHIDs) to omit rows which have no story references. These story data
|
||||||
// rows are notifications or realtime alerts.
|
// rows are notifications or realtime alerts.
|
||||||
|
|
||||||
$ref_table = new PhabricatorFeedStoryReference();
|
$ref_table = new PhabricatorFeedStoryReference();
|
||||||
return qsprintf(
|
$joins[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
||||||
$ref_table->getTableName());
|
$ref_table->getTableName());
|
||||||
|
|
||||||
|
return $joins;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = array();
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
if ($this->filterPHIDs) {
|
if ($this->filterPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'ref.objectPHID IN (%Ls)',
|
'ref.objectPHID IN (%Ls)',
|
||||||
$this->filterPHIDs);
|
$this->filterPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->chronologicalKeys) {
|
if ($this->chronologicalKeys !== null) {
|
||||||
// NOTE: We want to use integers in the query so we can take advantage
|
// 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
|
// of keys, but can't use %d on 32-bit systems. Make sure all the keys
|
||||||
// are integers and then format them raw.
|
// are integers and then format them raw.
|
||||||
|
@ -73,21 +69,19 @@ final class PhabricatorFeedQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'ref.chronologicalKey IN (%Q)',
|
'ref.chronologicalKey IN (%Q)',
|
||||||
implode(', ', $keys));
|
implode(', ', $keys));
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
return $where;
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildGroupClause(AphrontDatabaseConnection $conn) {
|
||||||
if ($this->filterPHIDs) {
|
if ($this->filterPHIDs !== null) {
|
||||||
return qsprintf($conn_r, 'GROUP BY ref.chronologicalKey');
|
return qsprintf($conn, 'GROUP BY ref.chronologicalKey');
|
||||||
} else {
|
} 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'];
|
return $item['chronologicalKey'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPrimaryTableAlias() {
|
||||||
|
return 'story';
|
||||||
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
return 'PhabricatorFeedApplication';
|
return 'PhabricatorFeedApplication';
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ final class PhabricatorFeedSearchEngine
|
||||||
|
|
||||||
$phids = array_mergev($phids);
|
$phids = array_mergev($phids);
|
||||||
if ($phids) {
|
if ($phids) {
|
||||||
$query->setFilterPHIDs($phids);
|
$query->withFilterPHIDs($phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
|
|
@ -229,7 +229,7 @@ final class PhabricatorPeopleProfileViewController
|
||||||
$viewer) {
|
$viewer) {
|
||||||
|
|
||||||
$query = new PhabricatorFeedQuery();
|
$query = new PhabricatorFeedQuery();
|
||||||
$query->setFilterPHIDs(
|
$query->withFilterPHIDs(
|
||||||
array(
|
array(
|
||||||
$user->getPHID(),
|
$user->getPHID(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -73,7 +73,7 @@ final class PhabricatorProjectProfileController
|
||||||
|
|
||||||
$stories = id(new PhabricatorFeedQuery())
|
$stories = id(new PhabricatorFeedQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->setFilterPHIDs(
|
->withFilterPHIDs(
|
||||||
array(
|
array(
|
||||||
$project->getPHID(),
|
$project->getPHID(),
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in a new issue