Page MenuHomePhabricator

D10674.diff
No OneTemporary

D10674.diff

diff --git a/resources/sql/patches/20141010.phrequent.sql b/resources/sql/patches/20141010.phrequent.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/patches/20141010.phrequent.sql
@@ -0,0 +1,3 @@
+CREATE INDEX IDX_DATE_STARTED on {$NAMESPACE}_phrequent.phrequent_usertime (dateStarted);
+CREATE INDEX IDX_DATE_ENDED on {$NAMESPACE}_phrequent.phrequent_usertime (dateEnded);
+CREATE INDEX IDX_DATE_STARTED_ENDED on {$NAMESPACE}_phrequent.phrequent_usertime (dateStarted, dateEnded);
diff --git a/src/applications/phrequent/query/PhrequentSearchEngine.php b/src/applications/phrequent/query/PhrequentSearchEngine.php
--- a/src/applications/phrequent/query/PhrequentSearchEngine.php
+++ b/src/applications/phrequent/query/PhrequentSearchEngine.php
@@ -25,6 +25,22 @@
$saved->setParameter('order', $request->getStr('order'));
+ $saved->setParameter(
+ 'after',
+ id(new AphrontFormDateControl())
+ ->setName('after')
+ ->setAllowNull(true)
+ ->setUser($request->getUser())
+ ->readValueFromRequest($request));
+
+ $saved->setParameter(
+ 'before',
+ id(new AphrontFormDateControl())
+ ->setName('before')
+ ->setAllowNull(true)
+ ->setUser($request->getUser())
+ ->readValueFromRequest($request));
+
return $saved;
}
@@ -46,6 +62,16 @@
if ($order != null) {
$query->setOrder($order);
}
+
+ $after = $saved->getParameter('after');
+ if ($after != null) {
+ $query->afterDate($after);
+ }
+
+ $before = $saved->getParameter('before');
+ if ($before != null) {
+ $query->beforeDate($before);
+ }
return $query;
}
@@ -54,11 +80,15 @@
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
+ $user = $this->requireViewer();
+
$user_phids = $saved_query->getParameter('userPHIDs', array());
$ended = $saved_query->getParameter(
'ended', PhrequentUserTimeQuery::ENDED_ALL);
$order = $saved_query->getParameter(
'order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
+ $after = $saved_query->getParameter('after', null);
+ $before = $saved_query->getParameter('before', null);
$phids = array_merge($user_phids);
$handles = id(new PhabricatorHandleQuery())
@@ -84,7 +114,23 @@
->setLabel(pht('Order'))
->setName('order')
->setValue($order)
- ->setOptions(PhrequentUserTimeQuery::getOrderSearchOptions()));
+ ->setOptions(PhrequentUserTimeQuery::getOrderSearchOptions()))
+ ->appendChild(
+ id(new AphrontFormDateControl())
+ ->setLabel(pht('After'))
+ ->setName('after')
+ ->setUser($user)
+ ->setValue($after)
+ ->setAllowNull(true)
+ ->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY))
+ ->appendChild(
+ id(new AphrontFormDateControl())
+ ->setLabel(pht('Before'))
+ ->setName('before')
+ ->setUser($user)
+ ->setValue($before)
+ ->setAllowNull(true)
+ ->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY));
}
protected function getURI($path) {
diff --git a/src/applications/phrequent/query/PhrequentUserTimeQuery.php b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
--- a/src/applications/phrequent/query/PhrequentUserTimeQuery.php
+++ b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
@@ -16,13 +16,21 @@
const ENDED_NO = 1;
const ENDED_ALL = 2;
+ private $ids;
private $userPHIDs;
private $objectPHIDs;
+ private $afterDate;
+ private $beforeDate;
private $order = self::ORDER_ID_ASC;
private $ended = self::ENDED_ALL;
private $needPreemptingEvents;
+ public function withIDs($ids) {
+ $this->ids = $ids;
+ return $this;
+ }
+
public function withUserPHIDs($user_phids) {
$this->userPHIDs = $user_phids;
return $this;
@@ -33,6 +41,16 @@
return $this;
}
+ public function afterDate($after_date) {
+ $this->afterDate = $after_date;
+ return $this;
+ }
+
+ public function beforeDate($before_date) {
+ $this->beforeDate = $before_date;
+ return $this;
+ }
+
public function withEnded($ended) {
$this->ended = $ended;
return $this;
@@ -50,6 +68,13 @@
private function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array();
+
+ if ($this->ids) {
+ $where[] = qsprintf(
+ $conn,
+ 'id IN (%Ld)',
+ $this->ids);
+ }
if ($this->userPHIDs) {
$where[] = qsprintf(
@@ -81,6 +106,20 @@
default:
throw new Exception("Unknown ended '{$this->ended}'!");
}
+
+ if ($this->afterDate) {
+ $where[] = qsprintf(
+ $conn,
+ 'dateEnded > %d',
+ $this->afterDate);
+ }
+
+ if ($this->beforeDate) {
+ $where[] = qsprintf(
+ $conn,
+ 'dateStarted < %d',
+ $this->beforeDate);
+ }
$where[] = $this->buildPagingClause($conn);

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 23, 11:26 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7713024
Default Alt Text
D10674.diff (4 KB)

Event Timeline