From 5b2887b69b0e5cac4f476c83955e27ac31928eae Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 17 Mar 2014 15:53:07 -0700 Subject: [PATCH] Add "Date Updated" query fields for Maniphest Summary: Fixes T4637. - We already allow you to order by this column but don't have a key on it. Add one. - Expose UI for querying on ranges. Test Plan: - Ran some queries, got reasonable-looking results and no table scans. Reviewers: btrahan, bigo Reviewed By: bigo Subscribers: bigo, epriestley Maniphest Tasks: T4637 Differential Revision: https://secure.phabricator.com/D8557 --- .../sql/autopatches/20140317.mupdatedkey.sql | 2 ++ .../maniphest/query/ManiphestTaskQuery.php | 26 +++++++++++++++++++ .../query/ManiphestTaskSearchEngine.php | 21 +++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 resources/sql/autopatches/20140317.mupdatedkey.sql diff --git a/resources/sql/autopatches/20140317.mupdatedkey.sql b/resources/sql/autopatches/20140317.mupdatedkey.sql new file mode 100644 index 0000000000..404e753e83 --- /dev/null +++ b/resources/sql/autopatches/20140317.mupdatedkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_maniphest.maniphest_task + ADD KEY `key_dateModified` (dateModified); diff --git a/src/applications/maniphest/query/ManiphestTaskQuery.php b/src/applications/maniphest/query/ManiphestTaskQuery.php index 4126dafe86..740856b4aa 100644 --- a/src/applications/maniphest/query/ManiphestTaskQuery.php +++ b/src/applications/maniphest/query/ManiphestTaskQuery.php @@ -22,6 +22,8 @@ final class ManiphestTaskQuery private $includeNoProject = null; private $dateCreatedAfter; private $dateCreatedBefore; + private $dateModifiedAfter; + private $dateModifiedBefore; private $fullTextSearch = ''; @@ -153,6 +155,16 @@ final class ManiphestTaskQuery return $this; } + public function withDateModifiedBefore($date_modified_before) { + $this->dateModifiedBefore = $date_modified_before; + return $this; + } + + public function withDateModifiedAfter($date_modified_after) { + $this->dateModifiedAfter = $date_modified_after; + return $this; + } + public function loadPage() { // TODO: (T603) It is possible for a user to find the PHID of a project @@ -193,6 +205,20 @@ final class ManiphestTaskQuery $this->dateCreatedBefore); } + if ($this->dateModifiedAfter) { + $where[] = qsprintf( + $conn, + 'dateModified >= %d', + $this->dateModifiedAfter); + } + + if ($this->dateModifiedBefore) { + $where[] = qsprintf( + $conn, + 'dateModified <= %d', + $this->dateModifiedBefore); + } + $where[] = $this->buildPagingClause($conn); $where = $this->formatWhereClause($where); diff --git a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php index df9deff3c0..ce51d55820 100644 --- a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php +++ b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php @@ -64,6 +64,8 @@ final class ManiphestTaskSearchEngine $saved->setParameter('createdStart', $request->getStr('createdStart')); $saved->setParameter('createdEnd', $request->getStr('createdEnd')); + $saved->setParameter('modifiedStart', $request->getStr('modifiedStart')); + $saved->setParameter('modifiedEnd', $request->getStr('modifiedEnd')); $limit = $request->getInt('limit'); if ($limit > 0) { @@ -170,6 +172,17 @@ final class ManiphestTaskSearchEngine $query->withDateCreatedBefore($end); } + $mod_start = $this->parseDateTime($saved->getParameter('modifiedStart')); + $mod_end = $this->parseDateTime($saved->getParameter('modifiedEnd')); + + if ($mod_start) { + $query->withDateModifiedAfter($mod_start); + } + + if ($mod_end) { + $query->withDateModifiedBefore($mod_end); + } + $this->applyCustomFieldsToQuery($query, $saved); return $query; @@ -344,6 +357,14 @@ final class ManiphestTaskSearchEngine 'createdEnd', pht('Created Before')); + $this->buildDateRange( + $form, + $saved, + 'modifiedStart', + pht('Updated After'), + 'modifiedEnd', + pht('Updated Before')); + $form ->appendChild( id(new AphrontFormTextControl())