2012-02-17 19:21:38 +01:00
|
|
|
<?php
|
|
|
|
|
2012-09-13 19:15:08 +02:00
|
|
|
final class PhabricatorChatLogQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-06-02 23:00:08 +02:00
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
private $channelIDs;
|
2012-06-02 23:00:08 +02:00
|
|
|
private $maximumEpoch;
|
2012-02-17 19:21:38 +01:00
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
public function withChannelIDs(array $channel_ids) {
|
|
|
|
$this->channelIDs = $channel_ids;
|
2012-02-17 19:21:38 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-06-02 23:00:08 +02:00
|
|
|
public function withMaximumEpoch($epoch) {
|
|
|
|
$this->maximumEpoch = $epoch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadPage() {
|
2012-03-28 01:53:47 +02:00
|
|
|
$table = new PhabricatorChatLogEvent();
|
2012-02-17 19:21:38 +01:00
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
2012-06-02 23:00:08 +02:00
|
|
|
'SELECT * FROM %T e %Q %Q %Q',
|
2012-02-17 19:21:38 +01:00
|
|
|
$table->getTableName(),
|
2012-06-02 23:00:08 +02:00
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
2012-02-17 19:21:38 +01:00
|
|
|
|
|
|
|
$logs = $table->loadAllFromArray($data);
|
|
|
|
|
Allow policy-aware queries to prefilter results
Summary:
Provides a simple way for policy-aware queries to pre-filter results without needing to maintain separate cursors, and fixes a bunch of filter-related edge cases.
- For reverse-paged cursor queries, we previously reversed each individual set of results. If the final result set is built out of multiple pages, it's in the wrong order overall, with each page in the correct order in sequence. Instead, reverse everything at the end. This also simplifies construction of queries.
- `AphrontCursorPagerView` would always render a "<< First" link when paging backward, even if we were on the first page of results.
- Add a filtering hook to let queries perform in-application pre-policy filtering as simply as possible (i.e., without maintaing their own cursors over the result sets).
Test Plan: Made feed randomly prefilter half the results, and paged forward and backward. Observed correct result ordering, pagination, and next/previous links.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D3787
2012-10-23 21:01:11 +02:00
|
|
|
return $logs;
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
2012-06-02 23:00:08 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
if ($this->maximumEpoch) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'epoch <= %d',
|
|
|
|
$this->maximumEpoch);
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
if ($this->channelIDs) {
|
2012-02-17 19:21:38 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2013-02-22 15:59:17 +01:00
|
|
|
'channelID IN (%Ld)',
|
|
|
|
$this->channelIDs);
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|
|
|
|
|
2012-04-05 02:51:16 +02:00
|
|
|
return $this->formatWhereClause($where);
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|
|
|
|
}
|