diff --git a/src/applications/feed/query/PhabricatorFeedQuery.php b/src/applications/feed/query/PhabricatorFeedQuery.php --- a/src/applications/feed/query/PhabricatorFeedQuery.php +++ b/src/applications/feed/query/PhabricatorFeedQuery.php @@ -5,6 +5,8 @@ private $filterPHIDs; private $chronologicalKeys; + private $rangeMin; + private $rangeMax; public function withFilterPHIDs(array $phids) { $this->filterPHIDs = $phids; @@ -16,6 +18,12 @@ return $this; } + public function withEpochInRange($range_min, $range_max) { + $this->rangeMin = $range_min; + $this->rangeMax = $range_max; + return $this; + } + public function newResultObject() { return new PhabricatorFeedStoryData(); } @@ -74,6 +82,24 @@ 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; } diff --git a/src/applications/feed/query/PhabricatorFeedSearchEngine.php b/src/applications/feed/query/PhabricatorFeedSearchEngine.php --- a/src/applications/feed/query/PhabricatorFeedSearchEngine.php +++ b/src/applications/feed/query/PhabricatorFeedSearchEngine.php @@ -27,6 +27,12 @@ id(new PhabricatorProjectSearchField()) ->setLabel(pht('Include Projects')) ->setKey('projectPHIDs'), + id(new PhabricatorSearchDateControlField()) + ->setLabel(pht('Occurs After')) + ->setKey('rangeStart'), + id(new PhabricatorSearchDateControlField()) + ->setLabel(pht('Occurs Before')) + ->setKey('rangeEnd'), // NOTE: This is a legacy field retained only for backward // compatibility. Users can now run an equivalent query by searching for @@ -68,6 +74,12 @@ $query->withFilterPHIDs($phids); } + $range_min = $map['rangeStart']->getEpoch(); + $range_max = $map['rangeEnd']->getEpoch(); + if ($range_min || $range_max) { + $query->withEpochInRange($range_min, $range_max); + } + return $query; }