@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow users to query feed by a date range

Summary: Ref T12762.

Test Plan:
- Ran queries with start date, end date, both, neither.
- Used EXPLAIN to try to make sure doing the bitshift isn't going to be a performance issue.

{F4978842}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12762

Differential Revision: https://secure.phabricator.com/D18029

+56
+26
src/applications/feed/query/PhabricatorFeedQuery.php
··· 5 5 6 6 private $filterPHIDs; 7 7 private $chronologicalKeys; 8 + private $rangeMin; 9 + private $rangeMax; 8 10 9 11 public function withFilterPHIDs(array $phids) { 10 12 $this->filterPHIDs = $phids; ··· 13 15 14 16 public function withChronologicalKeys(array $keys) { 15 17 $this->chronologicalKeys = $keys; 18 + return $this; 19 + } 20 + 21 + public function withEpochInRange($range_min, $range_max) { 22 + $this->rangeMin = $range_min; 23 + $this->rangeMax = $range_max; 16 24 return $this; 17 25 } 18 26 ··· 72 80 $conn, 73 81 'ref.chronologicalKey IN (%Q)', 74 82 implode(', ', $keys)); 83 + } 84 + 85 + // NOTE: We may not have 64-bit PHP, so do the shifts in MySQL instead. 86 + // From EXPLAIN, it appears like MySQL is smart enough to compute the 87 + // result and make use of keys to execute the query. 88 + 89 + if ($this->rangeMin !== null) { 90 + $where[] = qsprintf( 91 + $conn, 92 + 'ref.chronologicalKey >= (%d << 32)', 93 + $this->rangeMin); 94 + } 95 + 96 + if ($this->rangeMax !== null) { 97 + $where[] = qsprintf( 98 + $conn, 99 + 'ref.chronologicalKey < (%d << 32)', 100 + $this->rangeMax); 75 101 } 76 102 77 103 return $where;
+30
src/applications/feed/query/PhabricatorFeedSearchEngine.php
··· 30 30 ->setDatasource(new PhabricatorProjectDatasource()) 31 31 ->setLabel(pht('Include Projects')) 32 32 ->setKey('projectPHIDs'), 33 + id(new PhabricatorSearchDateControlField()) 34 + ->setLabel(pht('Occurs After')) 35 + ->setKey('rangeStart'), 36 + id(new PhabricatorSearchDateControlField()) 37 + ->setLabel(pht('Occurs Before')) 38 + ->setKey('rangeEnd'), 33 39 34 40 // NOTE: This is a legacy field retained only for backward 35 41 // compatibility. If the projects field used EdgeLogic, we could use ··· 69 75 70 76 if ($phids) { 71 77 $query->withFilterPHIDs($phids); 78 + } 79 + 80 + $range_min = $map['rangeStart']; 81 + if ($range_min) { 82 + $range_min = $range_min->getEpoch(); 83 + } 84 + 85 + $range_max = $map['rangeEnd']; 86 + if ($range_max) { 87 + $range_max = $range_max->getEpoch(); 88 + } 89 + 90 + if ($range_min && $range_max) { 91 + if ($range_min > $range_max) { 92 + throw new PhabricatorSearchConstraintException( 93 + pht( 94 + 'The specified "Occurs Before" date is earlier in time than the '. 95 + 'specified "Occurs After" date, so this query can never match '. 96 + 'any results.')); 97 + } 98 + } 99 + 100 + if ($range_min || $range_max) { 101 + $query->withEpochInRange($range_min, $range_max); 72 102 } 73 103 74 104 return $query;