[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/query/policy/ -> PhabricatorCursorPagedPolicyAwareQuery.php (summary)

A query class which uses cursor-based paging. This paging is much more performant than offset-based paging in the presence of policy filtering.

File Size: 633 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 24 functions

  getPagingColumn()
  getPagingValue()
  getReversePaging()
  nextPage()
  setAfterID()
  getAfterID()
  setBeforeID()
  getBeforeID()
  getPagingViewer()
  buildLimitClause()
  buildPagingClause()
  buildOrderClause()
  didLoadResults()
  executeWithCursorPager()
  buildPagingClauseFromMultipleColumns()
  withApplicationSearchContainsConstraint()
  withApplicationSearchRangeConstraint()
  withApplicationSearchOrder()
  getApplicationSearchObjectPHIDColumn()
  getApplicationSearchMayJoinMultipleRows()
  buildApplicationSearchGroupClause()
  buildApplicationSearchJoinClause()
  buildApplicationSearchOrders()
  buildApplicationSearchPagination()

Functions
Functions that are not part of a class:

getPagingColumn()   X-Ref
No description

getPagingValue($result)   X-Ref
No description

getReversePaging()   X-Ref
No description

nextPage(array $page)   X-Ref
No description

setAfterID($object_id)   X-Ref
No description

getAfterID()   X-Ref
No description

setBeforeID($object_id)   X-Ref
No description

getBeforeID()   X-Ref
No description

getPagingViewer()   X-Ref
Get the viewer for making cursor paging queries.

NOTE: You should ONLY use this viewer to load cursor objects while
building paging queries.

Cursor paging can happen in two ways. First, the user can request a page
like `/stuff/?after=33`, which explicitly causes paging. Otherwise, we
can fall back to implicit paging if we filter some results out of a
result list because the user can't see them and need to go fetch some more
results to generate a large enough result list.

In the first case, want to use the viewer's policies to load the object.
This prevents an attacker from figuring out information about an object
they can't see by executing queries like `/stuff/?after=33&order=name`,
which would otherwise give them a hint about the name of the object.
Generally, if a user can't see an object, they can't use it to page.

In the second case, we need to load the object whether the user can see
it or not, because we need to examine new results. For example, if a user
loads `/stuff/` and we run a query for the first 100 items that they can
see, but the first 100 rows in the database aren't visible, we need to
be able to issue a query for the next 100 results. If we can't load the
cursor object, we'll fail or issue the same query over and over again.
So, generally, internal paging must bypass policy controls.

This method returns the appropriate viewer, based on the context in which
the paging is occuring.

return: PhabricatorUser Viewer for executing paging queries.

buildLimitClause(AphrontDatabaseConnection $conn_r)   X-Ref
No description

buildPagingClause(AphrontDatabaseConnection $conn_r)   X-Ref
No description

buildOrderClause(AphrontDatabaseConnection $conn_r)   X-Ref
No description

didLoadResults(array $results)   X-Ref
No description

executeWithCursorPager(AphrontCursorPagerView $pager)   X-Ref
No description

buildPagingClauseFromMultipleColumns(AphrontDatabaseConnection $conn,array $columns,array $options)   X-Ref
Simplifies the task of constructing a paging clause across multiple
columns. In the general case, this looks like:

A > a OR (A = a AND B > b) OR (A = a AND B = b AND C > c)

To build a clause, specify the name, type, and value of each column
to include:

$this->buildPagingClauseFromMultipleColumns(
$conn_r,
array(
array(
'name' => 'title',
'type' => 'string',
'value' => $cursor->getTitle(),
'reverse' => true,
),
array(
'name' => 'id',
'type' => 'int',
'value' => $cursor->getID(),
),
),
array(
'reversed' => $is_reversed,
));

This method will then return a composable clause for inclusion in WHERE.

param: AphrontDatabaseConnection Connection query will execute on.
param: list<map> Column description dictionaries.
param: map Additional constuction options.
return: string Query clause.

withApplicationSearchContainsConstraint(PhabricatorCustomFieldIndexStorage $index,$value)   X-Ref
Constrain the query with an ApplicationSearch index, requiring field values
contain at least one of the values in a set.

This constraint can build the most common types of queries, like:

- Find users with shirt sizes "X" or "XL".
- Find shoes with size "13".

param: PhabricatorCustomFieldIndexStorage Table where the index is stored.
param: string|list<string> One or more values to filter by.
return: this

withApplicationSearchRangeConstraint(PhabricatorCustomFieldIndexStorage $index,$min,$max)   X-Ref
Constrain the query with an ApplicationSearch index, requiring values
exist in a given range.

This constraint is useful for expressing date ranges:

- Find events between July 1st and July 7th.

The ends of the range are inclusive, so a `$min` of `3` and a `$max` of
`5` will match fields with values `3`, `4`, or `5`. Providing `null` for
either end of the range will leave that end of the constraint open.

param: PhabricatorCustomFieldIndexStorage Table where the index is stored.
param: int|null Minimum permissible value, inclusive.
param: int|null Maximum permissible value, inclusive.
return: this

withApplicationSearchOrder(PhabricatorCustomField $field,PhabricatorCustomFieldIndexStorage $index,$ascending)   X-Ref
Order the results by an ApplicationSearch index.

param: PhabricatorCustomField Field to which the index belongs.
param: PhabricatorCustomFieldIndexStorage Table where the index is stored.
param: bool True to sort ascending.
return: this

getApplicationSearchObjectPHIDColumn()   X-Ref
Get the name of the query's primary object PHID column, for constructing
JOIN clauses. Normally (and by default) this is just `"phid"`, but if the
query construction requires a table alias it may be something like
`"task.phid"`.

return: string Column name.

getApplicationSearchMayJoinMultipleRows()   X-Ref
Determine if the JOINs built by ApplicationSearch might cause each primary
object to return multiple result rows. Generally, this means the query
needs an extra GROUP BY clause.

return: bool True if the query may return multiple rows for each object.

buildApplicationSearchGroupClause(AphrontDatabaseConnection $conn_r)   X-Ref
Construct a GROUP BY clause appropriate for ApplicationSearch constraints.

param: AphrontDatabaseConnection Connection executing the query.
return: string Group clause.

buildApplicationSearchJoinClause(AphrontDatabaseConnection $conn_r)   X-Ref
Construct a JOIN clause appropriate for applying ApplicationSearch
constraints.

param: AphrontDatabaseConnection Connection executing the query.
return: string Join clause.

buildApplicationSearchOrders(AphrontDatabaseConnection $conn_r,$reverse)   X-Ref
No description

buildApplicationSearchPagination(AphrontDatabaseConnection $conn_r,$cursor)   X-Ref
No description



Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1