2011-07-05 08:35:18 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-02-15 17:48:14 -08:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-07-05 08:35:18 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
Rename "IDPaged" to "CursorPaged", "executeWithPager" to "executeWith[Cursor|Offset]Pager"
Summary:
I'm trying to make progress on the policy/visibility stuff since it's a blocker for Wikimedia.
First, I want to improve Projects so they can serve as policy groups (e.g., an object can have a visibility policy like "Visible to: members of project 'security'"). However, doing this without breaking anything or snowballing into a bigger change is a bit awkward because Projects are name-ordered and we have a Conduit API which does offset paging. Rather than breaking or rewriting this stuff, I want to just continue offset paging them for now.
So I'm going to make PhabricatorPolicyQuery extend PhabricatorOffsetPagedQuery, but can't currently since the `executeWithPager` methods would clash. These methods do different things anyway and are probably better with different names.
This also generally improves the names of these classes, since cursors are not necessarily IDs (in the feed case, they're "chronlogicalKeys", for example). I did leave some of the interals as "ID" since calling them "Cursor"s (e.g., `setAfterCursor()`) seemed a little wrong -- it should maybe be `setAfterCursorPosition()`. These APIs have very limited use and can easily be made more consistent later.
Test Plan: Browsed around various affected tools; any issues here should throw/fail in a loud/obvious way.
Reviewers: vrana, btrahan
Reviewed By: vrana
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D3177
2012-08-07 11:54:06 -07:00
|
|
|
final class PhabricatorFeedQuery extends PhabricatorCursorPagedPolicyQuery {
|
2011-07-05 08:35:18 -07:00
|
|
|
|
|
|
|
private $filterPHIDs;
|
|
|
|
|
|
|
|
public function setFilterPHIDs(array $phids) {
|
|
|
|
$this->filterPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
public function loadPage() {
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$story_table = new PhabricatorFeedStoryData();
|
|
|
|
$conn = $story_table->establishConnection('r');
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$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));
|
|
|
|
|
|
|
|
$results = PhabricatorFeedStory::loadAllFromRows($data);
|
|
|
|
|
|
|
|
return $this->processResults($results);
|
2012-02-15 17:48:14 -08:00
|
|
|
}
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
// 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.
|
2011-07-05 08:35:18 -07:00
|
|
|
|
|
|
|
$ref_table = new PhabricatorFeedStoryReference();
|
2012-07-02 15:41:19 -07:00
|
|
|
return qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
|
|
|
$ref_table->getTableName());
|
|
|
|
}
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2011-07-05 08:35:18 -07:00
|
|
|
$where = array();
|
2012-07-02 15:41:19 -07:00
|
|
|
|
2011-07-05 08:35:18 -07:00
|
|
|
if ($this->filterPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
2012-07-02 15:41:19 -07:00
|
|
|
$conn_r,
|
2011-07-05 08:35:18 -07:00
|
|
|
'ref.objectPHID IN (%Ls)',
|
|
|
|
$this->filterPHIDs);
|
|
|
|
}
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
return qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'GROUP BY ref.chronologicalKey');
|
|
|
|
}
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
protected function getPagingColumn() {
|
|
|
|
return 'ref.chronologicalKey';
|
|
|
|
}
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
protected function getPagingValue($item) {
|
|
|
|
return $item->getChronologicalKey();
|
2011-07-05 08:35:18 -07:00
|
|
|
}
|
2012-07-02 10:37:22 -07:00
|
|
|
|
2011-07-05 08:35:18 -07:00
|
|
|
}
|