jenkins-bot has submitted this change and it was merged.

Change subject: Limit query granularity
......................................................................


Limit query granularity

The special page already limits the granularity to one day since the
input validation doesn't recognize date strings including a time. But we
can do better and limit it in the backend code too.

Bug: T78808
Change-Id: I9bb85f39496596b5e1725adcdb5b51f38f8a4579
---
M ApiFeatureUsageQueryEngineElastica.php
1 file changed, 12 insertions(+), 4 deletions(-)

Approvals:
  CSteipp: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiFeatureUsageQueryEngineElastica.php 
b/ApiFeatureUsageQueryEngineElastica.php
index 3b38364..cdf84c7 100644
--- a/ApiFeatureUsageQueryEngineElastica.php
+++ b/ApiFeatureUsageQueryEngineElastica.php
@@ -47,13 +47,23 @@
        public function execute( $agent, MWTimestamp $start, MWTimestamp $end ) 
{
                $status = Status::newGood( array() );
 
+               # Force $start and $end to day boundaries
+               $oneday = new DateInterval( 'P1D' );
+               $start = clone $start;
+               $start->timestamp = clone $start->timestamp;
+               $start->timestamp->setTime( 0, 0, 0 );
+               $end = clone $end;
+               $end->timestamp = clone $end->timestamp;
+               $end->timestamp->setTime( 0, 0, 0 );
+               $end->timestamp->add( $oneday )->sub( new DateInterval( 'PT1S' 
) );
+
                $query = new Elastica\Query();
 
                $bools = new Elastica\Filter\Bool();
                $bools->addMust( new Elastica\Filter\Prefix( 
$this->options['agentField'], $agent ) );
                $bools->addMust( new Elastica\Filter\Range( 
$this->options['timestampField'], array(
-                       'from' => $start->getTimestamp( TS_ISO_8601 ),
-                       'to' => $end->getTimestamp( TS_ISO_8601 ),
+                       'gte' => $start->getTimestamp( TS_ISO_8601 ),
+                       'lte' => $end->getTimestamp( TS_ISO_8601 ),
                ) ) );
                $query->setQuery( new Elastica\Query\Filtered( null, $bools ) );
 
@@ -78,8 +88,6 @@
                $indexes = array();
                $skippedAny = false;
                $s = clone $start->timestamp;
-               $s->setTime( 0, 0, 0 );
-               $oneday = new DateInterval( 'P1D' );
                while ( $s <= $end->timestamp ) {
                        $index = $this->options['indexPrefix'] . $s->format( 
$this->options['indexFormat'] );
                        if ( in_array( $index, $allIndexes ) ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/188839
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9bb85f39496596b5e1725adcdb5b51f38f8a4579
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ApiFeatureUsage
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to