From 75bc86589f10dd520bba41dc52bd3458e22b1f6a Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 30 Jan 2018 11:47:55 -0800 Subject: [PATCH] Add date range filtering for activity, push, and pull logs Summary: Ref T13049. This is just a general nice-to-have so you don't have to export a 300MB file if you want to check the last month of data or whatever. Test Plan: Applied filters to all three logs, got appropriate date-range result sets. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13049 Differential Revision: https://secure.phabricator.com/D18970 --- .../query/DiffusionPullLogSearchEngine.php | 12 ++++++++++ .../query/PhabricatorPeopleLogQuery.php | 22 +++++++++++++++++++ .../PhabricatorPeopleLogSearchEngine.php | 12 ++++++++++ .../PhabricatorRepositoryPullEventQuery.php | 22 +++++++++++++++++++ .../PhabricatorRepositoryPushLogQuery.php | 22 +++++++++++++++++++ ...abricatorRepositoryPushLogSearchEngine.php | 12 ++++++++++ .../storage/PhabricatorRepositoryPushLog.php | 3 +++ 7 files changed, 105 insertions(+) diff --git a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php index fc7cee52ce..db5d4b9fcb 100644 --- a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php +++ b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php @@ -26,6 +26,12 @@ final class DiffusionPullLogSearchEngine $query->withPullerPHIDs($map['pullerPHIDs']); } + if ($map['createdStart'] || $map['createdEnd']) { + $query->withEpochBetween( + $map['createdStart'], + $map['createdEnd']); + } + return $query; } @@ -44,6 +50,12 @@ final class DiffusionPullLogSearchEngine ->setLabel(pht('Pullers')) ->setDescription( pht('Search for pull logs by specific users.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd'), ); } diff --git a/src/applications/people/query/PhabricatorPeopleLogQuery.php b/src/applications/people/query/PhabricatorPeopleLogQuery.php index e6e2506bee..fc6a87b335 100644 --- a/src/applications/people/query/PhabricatorPeopleLogQuery.php +++ b/src/applications/people/query/PhabricatorPeopleLogQuery.php @@ -9,6 +9,8 @@ final class PhabricatorPeopleLogQuery private $sessionKeys; private $actions; private $remoteAddressPrefix; + private $dateCreatedMin; + private $dateCreatedMax; public function withActorPHIDs(array $actor_phids) { $this->actorPHIDs = $actor_phids; @@ -40,6 +42,12 @@ final class PhabricatorPeopleLogQuery return $this; } + public function withDateCreatedBetween($min, $max) { + $this->dateCreatedMin = $min; + $this->dateCreatedMax = $max; + return $this; + } + public function newResultObject() { return new PhabricatorUserLog(); } @@ -94,6 +102,20 @@ final class PhabricatorPeopleLogQuery $this->remoteAddressPrefix); } + if ($this->dateCreatedMin !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated >= %d', + $this->dateCreatedMin); + } + + if ($this->dateCreatedMax !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated <= %d', + $this->dateCreatedMax); + } + return $where; } diff --git a/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php b/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php index 1a3ae4dea1..b052456cd3 100644 --- a/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php +++ b/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php @@ -54,6 +54,12 @@ final class PhabricatorPeopleLogSearchEngine $query->withSessionKeys($map['sessions']); } + if ($map['createdStart'] || $map['createdEnd']) { + $query->withDateCreatedBetween( + $map['createdStart'], + $map['createdEnd']); + } + return $query; } @@ -82,6 +88,12 @@ final class PhabricatorPeopleLogSearchEngine ->setKey('sessions') ->setLabel(pht('Sessions')) ->setDescription(pht('Search for activity in particular sessions.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd'), ); } diff --git a/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php b/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php index af60ee0383..ce14a6f831 100644 --- a/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php @@ -7,6 +7,8 @@ final class PhabricatorRepositoryPullEventQuery private $phids; private $repositoryPHIDs; private $pullerPHIDs; + private $epochMin; + private $epochMax; public function withIDs(array $ids) { $this->ids = $ids; @@ -28,6 +30,12 @@ final class PhabricatorRepositoryPullEventQuery return $this; } + public function withEpochBetween($min, $max) { + $this->epochMin = $min; + $this->epochMax = $max; + return $this; + } + public function newResultObject() { return new PhabricatorRepositoryPullEvent(); } @@ -103,6 +111,20 @@ final class PhabricatorRepositoryPullEventQuery $this->pullerPHIDs); } + if ($this->epochMin !== null) { + $where[] = qsprintf( + $conn, + 'epoch >= %d', + $this->epochMin); + } + + if ($this->epochMax !== null) { + $where[] = qsprintf( + $conn, + 'epoch <= %d', + $this->epochMax); + } + return $where; } diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php index 2c5f7b0d0d..cb097fae2f 100644 --- a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php @@ -10,6 +10,8 @@ final class PhabricatorRepositoryPushLogQuery private $refTypes; private $newRefs; private $pushEventPHIDs; + private $epochMin; + private $epochMax; public function withIDs(array $ids) { $this->ids = $ids; @@ -46,6 +48,12 @@ final class PhabricatorRepositoryPushLogQuery return $this; } + public function withEpochBetween($min, $max) { + $this->epochMin = $min; + $this->epochMax = $max; + return $this; + } + public function newResultObject() { return new PhabricatorRepositoryPushLog(); } @@ -127,6 +135,20 @@ final class PhabricatorRepositoryPushLogQuery $this->newRefs); } + if ($this->epochMin !== null) { + $where[] = qsprintf( + $conn, + 'epoch >= %d', + $this->epochMin); + } + + if ($this->epochMax !== null) { + $where[] = qsprintf( + $conn, + 'epoch <= %d', + $this->epochMax); + } + return $where; } diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php index b2234ab6c7..8ad76987f9 100644 --- a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php @@ -26,6 +26,12 @@ final class PhabricatorRepositoryPushLogSearchEngine $query->withPusherPHIDs($map['pusherPHIDs']); } + if ($map['createdStart'] || $map['createdEnd']) { + $query->withEpochBetween( + $map['createdStart'], + $map['createdEnd']); + } + return $query; } @@ -44,6 +50,12 @@ final class PhabricatorRepositoryPushLogSearchEngine ->setLabel(pht('Pushers')) ->setDescription( pht('Search for pull logs by specific users.')), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd'), ); } diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php index 81a564a91f..c2d3456da6 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php +++ b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php @@ -124,6 +124,9 @@ final class PhabricatorRepositoryPushLog 'key_pusher' => array( 'columns' => array('pusherPHID'), ), + 'key_epoch' => array( + 'columns' => array('epoch'), + ), ), ) + parent::getConfiguration(); }