Changeset View
Changeset View
Standalone View
Standalone View
src/applications/feed/query/PhabricatorFeedQuery.php
| <?php | <?php | ||||
| final class PhabricatorFeedQuery | final class PhabricatorFeedQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $filterPHIDs; | private $filterPHIDs; | ||||
| private $chronologicalKeys; | private $chronologicalKeys; | ||||
| private $rangeMin; | |||||
| private $rangeMax; | |||||
| public function withFilterPHIDs(array $phids) { | public function withFilterPHIDs(array $phids) { | ||||
| $this->filterPHIDs = $phids; | $this->filterPHIDs = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withChronologicalKeys(array $keys) { | public function withChronologicalKeys(array $keys) { | ||||
| $this->chronologicalKeys = $keys; | $this->chronologicalKeys = $keys; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withEpochInRange($range_min, $range_max) { | |||||
| $this->rangeMin = $range_min; | |||||
| $this->rangeMax = $range_max; | |||||
| return $this; | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorFeedStoryData(); | return new PhabricatorFeedStoryData(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| // NOTE: We return raw rows from this method, which is a little unusual. | // NOTE: We return raw rows from this method, which is a little unusual. | ||||
| return $this->loadStandardPageRows($this->newResultObject()); | return $this->loadStandardPageRows($this->newResultObject()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if ($this->chronologicalKeys !== null) { | ||||
| } | } | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'ref.chronologicalKey IN (%Q)', | 'ref.chronologicalKey IN (%Q)', | ||||
| implode(', ', $keys)); | implode(', ', $keys)); | ||||
| } | } | ||||
| // NOTE: We may not have 64-bit PHP, so do the shifts in MySQL instead. | |||||
| // From EXPLAIN, it appears like MySQL is smart enough to compute the | |||||
| // result and make use of keys to execute the query. | |||||
| if ($this->rangeMin !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'ref.chronologicalKey >= (%d << 32)', | |||||
| $this->rangeMin); | |||||
| } | |||||
| if ($this->rangeMax !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'ref.chronologicalKey < (%d << 32)', | |||||
| $this->rangeMax); | |||||
| } | |||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function buildGroupClause(AphrontDatabaseConnection $conn) { | protected function buildGroupClause(AphrontDatabaseConnection $conn) { | ||||
| if ($this->filterPHIDs !== null) { | if ($this->filterPHIDs !== null) { | ||||
| return qsprintf($conn, 'GROUP BY ref.chronologicalKey'); | return qsprintf($conn, 'GROUP BY ref.chronologicalKey'); | ||||
| } else { | } else { | ||||
| return qsprintf($conn, 'GROUP BY story.chronologicalKey'); | return qsprintf($conn, 'GROUP BY story.chronologicalKey'); | ||||
| ▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines | |||||