1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
epriestley 2012-08-07 11:54:06 -07:00
parent 8ab1789329
commit ed4a155c91
21 changed files with 35 additions and 34 deletions

View file

@ -23,6 +23,7 @@ phutil_register_library_map(array(
'AphrontContextBarView' => 'view/layout/AphrontContextBarView.php',
'AphrontController' => 'aphront/AphrontController.php',
'AphrontCrumbsView' => 'view/layout/AphrontCrumbsView.php',
'AphrontCursorPagerView' => 'view/control/AphrontCursorPagerView.php',
'AphrontDefaultApplicationConfiguration' => 'aphront/configuration/AphrontDefaultApplicationConfiguration.php',
'AphrontDialogResponse' => 'aphront/response/AphrontDialogResponse.php',
'AphrontDialogView' => 'view/AphrontDialogView.php',
@ -57,7 +58,6 @@ phutil_register_library_map(array(
'AphrontHeadsupActionListView' => 'view/layout/headsup/AphrontHeadsupActionListView.php',
'AphrontHeadsupActionView' => 'view/layout/headsup/AphrontHeadsupActionView.php',
'AphrontHeadsupView' => 'view/layout/headsup/AphrontHeadsupView.php',
'AphrontIDPagerView' => 'view/control/AphrontIDPagerView.php',
'AphrontIsolatedDatabaseConnectionTestCase' => 'infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php',
'AphrontIsolatedHTTPSink' => 'aphront/sink/AphrontIsolatedHTTPSink.php',
'AphrontJSONResponse' => 'aphront/response/AphrontJSONResponse.php',
@ -606,6 +606,7 @@ phutil_register_library_map(array(
'PhabricatorCountdownEditController' => 'applications/countdown/controller/PhabricatorCountdownEditController.php',
'PhabricatorCountdownListController' => 'applications/countdown/controller/PhabricatorCountdownListController.php',
'PhabricatorCountdownViewController' => 'applications/countdown/controller/PhabricatorCountdownViewController.php',
'PhabricatorCursorPagedPolicyQuery' => 'infrastructure/query/policy/PhabricatorCursorPagedPolicyQuery.php',
'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php',
'PhabricatorDaemonCombinedLogController' => 'applications/daemon/controller/PhabricatorDaemonCombinedLogController.php',
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
@ -734,7 +735,6 @@ phutil_register_library_map(array(
'PhabricatorHash' => 'infrastructure/util/PhabricatorHash.php',
'PhabricatorHelpController' => 'applications/help/controller/PhabricatorHelpController.php',
'PhabricatorHelpKeyboardShortcutController' => 'applications/help/controller/PhabricatorHelpKeyboardShortcutController.php',
'PhabricatorIDPagedPolicyQuery' => 'infrastructure/query/policy/PhabricatorIDPagedPolicyQuery.php',
'PhabricatorIRCBot' => 'infrastructure/daemon/irc/PhabricatorIRCBot.php',
'PhabricatorIRCDifferentialNotificationHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCDifferentialNotificationHandler.php',
'PhabricatorIRCHandler' => 'infrastructure/daemon/irc/handler/PhabricatorIRCHandler.php',
@ -1168,6 +1168,7 @@ phutil_register_library_map(array(
'AphrontCalendarMonthView' => 'AphrontView',
'AphrontContextBarView' => 'AphrontView',
'AphrontCrumbsView' => 'AphrontView',
'AphrontCursorPagerView' => 'AphrontView',
'AphrontDefaultApplicationConfiguration' => 'AphrontApplicationConfiguration',
'AphrontDialogResponse' => 'AphrontResponse',
'AphrontDialogView' => 'AphrontView',
@ -1201,7 +1202,6 @@ phutil_register_library_map(array(
'AphrontHeadsupActionListView' => 'AphrontView',
'AphrontHeadsupActionView' => 'AphrontView',
'AphrontHeadsupView' => 'AphrontView',
'AphrontIDPagerView' => 'AphrontView',
'AphrontIsolatedDatabaseConnectionTestCase' => 'PhabricatorTestCase',
'AphrontIsolatedHTTPSink' => 'AphrontHTTPSink',
'AphrontJSONResponse' => 'AphrontResponse',
@ -1667,7 +1667,7 @@ phutil_register_library_map(array(
1 => 'PhabricatorPolicyInterface',
),
'PhabricatorChatLogEventType' => 'PhabricatorChatLogConstants',
'PhabricatorChatLogQuery' => 'PhabricatorIDPagedPolicyQuery',
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyQuery',
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
'PhabricatorConduitConnectionLog' => 'PhabricatorConduitDAO',
@ -1686,6 +1686,7 @@ phutil_register_library_map(array(
'PhabricatorCountdownEditController' => 'PhabricatorCountdownController',
'PhabricatorCountdownListController' => 'PhabricatorCountdownController',
'PhabricatorCountdownViewController' => 'PhabricatorCountdownController',
'PhabricatorCursorPagedPolicyQuery' => 'PhabricatorPolicyQuery',
'PhabricatorDaemon' => 'PhutilDaemon',
'PhabricatorDaemonCombinedLogController' => 'PhabricatorDaemonController',
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
@ -1741,7 +1742,7 @@ phutil_register_library_map(array(
'PhabricatorFeedController' => 'PhabricatorController',
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',
'PhabricatorFeedQuery' => 'PhabricatorIDPagedPolicyQuery',
'PhabricatorFeedQuery' => 'PhabricatorCursorPagedPolicyQuery',
'PhabricatorFeedStory' => 'PhabricatorPolicyInterface',
'PhabricatorFeedStoryAggregate' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory',
@ -1795,7 +1796,6 @@ phutil_register_library_map(array(
'PhabricatorGoodForNothingWorker' => 'PhabricatorWorker',
'PhabricatorHelpController' => 'PhabricatorController',
'PhabricatorHelpKeyboardShortcutController' => 'PhabricatorHelpController',
'PhabricatorIDPagedPolicyQuery' => 'PhabricatorPolicyQuery',
'PhabricatorIRCBot' => 'PhabricatorDaemon',
'PhabricatorIRCDifferentialNotificationHandler' => 'PhabricatorIRCHandler',
'PhabricatorIRCLogHandler' => 'PhabricatorIRCHandler',
@ -1911,7 +1911,7 @@ phutil_register_library_map(array(
'PhabricatorPasteController' => 'PhabricatorController',
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
'PhabricatorPasteListController' => 'PhabricatorPasteController',
'PhabricatorPasteQuery' => 'PhabricatorIDPagedPolicyQuery',
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyQuery',
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
'PhabricatorPeopleController' => 'PhabricatorController',
'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',

View file

@ -16,7 +16,7 @@
* limitations under the License.
*/
final class PhabricatorChatLogQuery extends PhabricatorIDPagedPolicyQuery {
final class PhabricatorChatLogQuery extends PhabricatorCursorPagedPolicyQuery {
private $channels;
private $maximumEpoch;

View file

@ -32,7 +32,7 @@ final class PhabricatorChatLogChannelLogController
$uri = clone $request->getRequestURI();
$uri->setQueryParams(array());
$pager = new AphrontIDPagerView();
$pager = new AphrontCursorPagerView();
$pager->setURI($uri);
$pager->setPageSize(250);
@ -46,7 +46,7 @@ final class PhabricatorChatLogChannelLogController
$pager->setAfterID($after);
$pager->setBeforeID($before);
$logs = $query->executeWithPager($pager);
$logs = $query->executeWithCursorPager($pager);
// Show chat logs oldest-first.
$logs = array_reverse($logs);

View file

@ -35,7 +35,7 @@ final class PhabricatorChatLogEvent
public function getPolicy($capability) {
// TODO: This is sort of silly and mostly just so that we can use
// IDPagedPolicyQuery; once we implement Channel objects we should
// CursorPagedPolicyQuery; once we implement Channel objects we should
// just delegate policy to them.
return PhabricatorPolicies::POLICY_PUBLIC;
}

View file

@ -402,11 +402,11 @@ final class PhabricatorDirectoryMainController
$feed_query->setFilterPHIDs($phids);
}
$pager = new AphrontIDPagerView();
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$pager->setPageSize(200);
$feed = $feed_query->executeWithPager($pager);
$feed = $feed_query->executeWithCursorPager($pager);
$builder = new PhabricatorFeedBuilder($feed);
$builder->setUser($user);

View file

@ -41,7 +41,7 @@ final class DrydockLogController extends DrydockController {
$pager->setOffset($request->getInt('offset'));
$pager->setURI($request->getRequestURI(), 'offset');
$logs = $query->executeWithPager($pager);
$logs = $query->executeWithOffsetPager($pager);
$rows = array();
foreach ($logs as $log) {

View file

@ -16,7 +16,7 @@
* limitations under the License.
*/
final class PhabricatorFeedQuery extends PhabricatorIDPagedPolicyQuery {
final class PhabricatorFeedQuery extends PhabricatorCursorPagedPolicyQuery {
private $filterPHIDs;

View file

@ -93,7 +93,7 @@ final class HeraldHomeController extends HeraldController {
$pager->setURI($request->getRequestURI(), 'offset');
$pager->setOffset($request->getStr('offset'));
$rules = $query->executeWithPager($pager);
$rules = $query->executeWithOffsetPager($pager);
$need_phids = mpull($rules, 'getAuthorPHID');
$handles = id(new PhabricatorObjectHandleData($need_phids))

View file

@ -36,7 +36,7 @@ final class HeraldRuleEditHistoryController extends HeraldController {
$pager->setURI($request->getRequestURI(), 'offset');
$pager->setOffset($request->getStr('offset'));
$edits = $edit_query->executeWithPager($pager);
$edits = $edit_query->executeWithOffsetPager($pager);
$need_phids = mpull($edits, 'getEditorPHID');
$handles = id(new PhabricatorObjectHandleData($need_phids))

View file

@ -54,7 +54,7 @@ final class PhabricatorNotificationListController
break;
}
$notifications = $query->executeWithPager($pager);
$notifications = $query->executeWithOffsetPager($pager);
if ($notifications) {
$builder = new PhabricatorNotificationBuilder($notifications);

View file

@ -40,7 +40,7 @@ extends PhabricatorOAuthClientBaseController {
$query = new PhabricatorOAuthServerClientQuery();
$query->withCreatorPHIDs(array($current_user->getPHID()));
$clients = $query->executeWithPager($pager);
$clients = $query->executeWithOffsetPager($pager);
$rows = array();
$rowc = array();

View file

@ -40,7 +40,7 @@ extends PhabricatorOAuthClientAuthorizationBaseController {
$query = new PhabricatorOAuthClientAuthorizationQuery();
$query->withUserPHIDs(array($current_user->getPHID()));
$authorizations = $query->executeWithPager($pager);
$authorizations = $query->executeWithOffsetPager($pager);
$client_authorizations = mpull($authorizations, null, 'getClientPHID');
$client_phids = array_keys($client_authorizations);

View file

@ -73,7 +73,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
$request = $this->getRequest();
$user = $request->getUser();
$pager = new AphrontIDPagerView();
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$query = new PhabricatorPasteQuery();
@ -95,10 +95,10 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
break;
case 'my':
$query->withAuthorPHIDs(array($user->getPHID()));
$paste_list = $query->executeWithPager($pager);
$paste_list = $query->executeWithCursorPager($pager);
break;
case 'all':
$paste_list = $query->executeWithPager($pager);
$paste_list = $query->executeWithCursorPager($pager);
break;
}

View file

@ -16,7 +16,7 @@
* limitations under the License.
*/
final class PhabricatorPasteQuery extends PhabricatorIDPagedPolicyQuery {
final class PhabricatorPasteQuery extends PhabricatorCursorPagedPolicyQuery {
private $pasteIDs;
private $authorPHIDs;

View file

@ -39,7 +39,7 @@ final class PhabricatorPeopleListController
$users = id(new PhabricatorPeopleQuery())
->needPrimaryEmail(true)
->executeWithPager($pager);
->executeWithOffsetPager($pager);
$rows = array();
foreach ($users as $user) {

View file

@ -31,7 +31,7 @@ final class PhameAllBlogListController
$blogs = id(new PhameBlogQuery())
->needBloggers(true)
->executeWithPager($this->getPager());
->executeWithOffsetPager($this->getPager());
$this->setBlogs($blogs);
$page_title = 'All Blogs';

View file

@ -51,7 +51,7 @@ final class PhameUserBlogListController
$blogs = id(new PhameBlogQuery())
->withPHIDs($blog_phids)
->needBloggers(true)
->executeWithPager($this->getPager());
->executeWithOffsetPager($this->getPager());
$this->setBlogs($blogs);

View file

@ -73,7 +73,7 @@ abstract class PhamePostListBaseController
protected function buildPostListPageResponse() {
$pager = $this->getPager();
$query = $this->getPhamePostQuery();
$posts = $query->executeWithPager($pager);
$posts = $query->executeWithOffsetPager($pager);
$bloggers = $this->loadBloggersFromPosts($posts);

View file

@ -47,7 +47,7 @@ abstract class PhabricatorOffsetPagedQuery extends PhabricatorQuery {
}
}
final public function executeWithPager(AphrontPagerView $pager) {
final public function executeWithOffsetPager(AphrontPagerView $pager) {
$this->setLimit($pager->getPageSize() + 1);
$this->setOffset($pager->getOffset());

View file

@ -17,10 +17,11 @@
*/
/**
* A query class which uses ID-based paging. This paging is much more performant
* than offset-based paging in the presence of policy filtering.
* A query class which uses cursor-based paging. This paging is much more
* performant than offset-based paging in the presence of policy filtering.
*/
abstract class PhabricatorIDPagedPolicyQuery extends PhabricatorPolicyQuery {
abstract class PhabricatorCursorPagedPolicyQuery
extends PhabricatorPolicyQuery {
private $afterID;
private $beforeID;
@ -101,7 +102,7 @@ abstract class PhabricatorIDPagedPolicyQuery extends PhabricatorPolicyQuery {
}
final public function executeWithPager(AphrontIDPagerView $pager) {
final public function executeWithCursorPager(AphrontCursorPagerView $pager) {
$this->setLimit($pager->getPageSize() + 1);
if ($pager->getAfterID()) {

View file

@ -16,7 +16,7 @@
* limitations under the License.
*/
final class AphrontIDPagerView extends AphrontView {
final class AphrontCursorPagerView extends AphrontView {
private $afterID;
private $beforeID;