Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/130093

Change subject: API: Fix queries for list=allusers&auactiveusers
......................................................................

API: Fix queries for list=allusers&auactiveusers

The query introduced to support the auactiveusers is itself broken (it
counts every edit multiple times when combined with the group filters or
auprop=groups or auprop=rights, or for users with multiple rows in
ipblocks) and it breaks auprop=groups and auprop=rights.

I can't come up with a query that will fix both of these issues and
maintain the pre-filtering behavior[1] and still remain efficient. So
let's lose the pre-filtering, which seems to result in a query that
isn't any more unreasonable than the old broken query was (which seems
to be very faint praise).

This change in the pre-filtering behavior isn't considered a BC break
since the API has long been explicitly allowed to return fewer results
than requested while still continuing.

 [1]: Meaning that specifying a limit of N gives you the first N users
   with recent edits, rather than taking the first N users (regardless of
   edits) and returning the subset that have recent edits.

Bug: 64505
Bug: 64507
Change-Id: I461e92819188c311cbb3853bc6bfad45962c8d7b
---
M includes/api/ApiQueryAllUsers.php
1 file changed, 22 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/93/130093/1

diff --git a/includes/api/ApiQueryAllUsers.php 
b/includes/api/ApiQueryAllUsers.php
index df8db16..2d74b23 100644
--- a/includes/api/ApiQueryAllUsers.php
+++ b/includes/api/ApiQueryAllUsers.php
@@ -71,14 +71,10 @@
                $from = is_null( $params['from'] ) ? null : 
$this->getCanonicalUserName( $params['from'] );
                $to = is_null( $params['to'] ) ? null : 
$this->getCanonicalUserName( $params['to'] );
 
-               # MySQL doesn't seem to use 'equality propagation' here, so 
like the
-               # ActiveUsers special page, we have to use rc_user_text for 
some cases.
-               $userFieldToSort = $params['activeusers'] ? 'rc_user_text' : 
'user_name';
-
-               $this->addWhereRange( $userFieldToSort, $dir, $from, $to );
+               $this->addWhereRange( 'user_name', $dir, $from, $to );
 
                if ( !is_null( $params['prefix'] ) ) {
-                       $this->addWhere( $userFieldToSort .
+                       $this->addWhere( 'user_name' .
                                $db->buildLike( $this->getCanonicalUserName( 
$params['prefix'] ), $db->anyString() ) );
                }
 
@@ -156,19 +152,19 @@
 
                if ( $params['activeusers'] ) {
                        global $wgActiveUserDays;
-                       $this->addTables( 'recentchanges' );
 
-                       $this->addJoinConds( array( 'recentchanges' => array(
-                               'INNER JOIN', 'rc_user_text=user_name'
-                       ) ) );
-
-                       $this->addFields( array( 'recentedits' => 'COUNT(*)' ) 
);
-
-                       $this->addWhere( 'rc_log_type IS NULL OR rc_log_type != 
' . $db->addQuotes( 'newusers' ) );
                        $timestamp = $db->timestamp( wfTimestamp( TS_UNIX ) - 
$wgActiveUserDays * 24 * 3600 );
-                       $this->addWhere( 'rc_timestamp >= ' . $db->addQuotes( 
$timestamp ) );
-
-                       $this->addOption( 'GROUP BY', $userFieldToSort );
+                       $this->addFields( array(
+                               'recentedits' => '(' . $db->selectSQLText(
+                                       'recentchanges',
+                                       'COUNT(*)',
+                                       array(
+                                               'rc_user_text = user_name',
+                                               'rc_log_type IS NULL OR 
rc_log_type != ' . $db->addQuotes( 'newusers' ),
+                                               'rc_timestamp >= ' . 
$db->addQuotes( $timestamp ),
+                                       )
+                               ) . ')' )
+                       );
                }
 
                $this->addOption( 'LIMIT', $sqlLimit );
@@ -204,8 +200,12 @@
                        if ( $lastUser !== $row->user_name ) {
                                // Save the last pass's user data
                                if ( is_array( $lastUserData ) ) {
-                                       $fit = $result->addValue( array( 
'query', $this->getModuleName() ),
-                                               null, $lastUserData );
+                                       if ( !$params['activeusers'] || 
$lastUserData['recenteditcount'] > 0 ) {
+                                               $fit = $result->addValue( 
array( 'query', $this->getModuleName() ),
+                                                       null, $lastUserData );
+                                       } else {
+                                               $fit = true;
+                                       }
 
                                        $lastUserData = null;
 
@@ -303,7 +303,9 @@
                        }
                }
 
-               if ( is_array( $lastUserData ) ) {
+               if ( is_array( $lastUserData ) &&
+                       ( !$params['activeusers'] || 
$lastUserData['recenteditcount'] > 0 )
+               ) {
                        $fit = $result->addValue( array( 'query', 
$this->getModuleName() ),
                                null, $lastUserData );
                        if ( !$fit ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I461e92819188c311cbb3853bc6bfad45962c8d7b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to