API: Fix up r46825:
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 9 Feb 2009 14:07:18 +0000 (14:07 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 9 Feb 2009 14:07:18 +0000 (14:07 +0000)
* put the tables in the right order
* JOIN on user_text as well for better index usage
* Force the index on the recentchanges table as well
* Don't ORDER BY rev_user_text if it's constant

includes/api/ApiQueryUserContributions.php

index 19a38c1..62c8cc5 100644 (file)
@@ -141,8 +141,7 @@ class ApiQueryContributions extends ApiQueryBase {
                // We're after the revision table, and the corresponding page
                // row for anything we retrieve. We may also need the
                // recentchanges row.
-               // Tables have to be in this order for STRAIGHT_JOIN
-               $this->addTables(array('revision', 'page'));
+               $tables = array('page', 'revision'); // Order may change
                $this->addWhere('page_id=rev_page');
 
                // Handle continue parameter
@@ -169,7 +168,8 @@ class ApiQueryContributions extends ApiQueryBase {
                // ... and in the specified timeframe.
                // Ensure the same sort order for rev_user_text and rev_timestamp
                // so our query is indexed
-               $this->addWhereRange('rev_user_text', $this->params['dir'], null, null);
+               if($this->multiUserMode)
+                       $this->addWhereRange('rev_user_text', $this->params['dir'], null, null);
                $this->addWhereRange('rev_timestamp',
                        $this->params['dir'], $this->params['start'], $this->params['end'] );
                $this->addWhereFld('page_namespace', $this->params['namespace']);
@@ -187,7 +187,7 @@ class ApiQueryContributions extends ApiQueryBase {
                        $this->addWhereIf('rc_patrolled != 0', isset($show['patrolled']));
                }
                $this->addOption('LIMIT', $this->params['limit'] + 1);
-               $this->addOption('USE INDEX', array('revision' => 'usertext_timestamp'));
+               $index['revision'] = 'usertext_timestamp';
 
                // Mandatory fields: timestamp allows request continuation
                // ns+title checks if the user has access rights for this page
@@ -205,23 +205,33 @@ class ApiQueryContributions extends ApiQueryBase {
                        global $wgUser;
                        if(!$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
                                $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
-                       $this->addTables('recentchanges');
                        // Use a redundant join condition on both
                        // timestamp and ID so we can use the timestamp
                        // index
+                       $index['recentchanges'] = 'rc_user_text';
                        if(isset($show['patrolled']) || isset($show['!patrolled']))
                        {
+                               // Put the tables in the right order for
+                               // STRAIGHT_JOIN
+                               $tables = array('revision', 'recentchanges', 'page');
                                $this->addOption('STRAIGHT_JOIN');
+                               $this->addWhere('rc_user_text=rev_user_text');
                                $this->addWhere('rc_timestamp=rev_timestamp');
                                $this->addWhere('rc_this_oldid=rev_id');
                        }
                        else
+                       {
+                               $tables[] = 'recentchanges';
                                $this->addJoinConds(array('recentchanges' => array(
                                        'LEFT JOIN', array(
+                                               'rc_user_text=rev_user_text',
                                                'rc_timestamp=rev_timestamp',
                                                'rc_this_oldid=rev_id'))));
+                       }
                }
 
+               $this->addTables($tables);
+               $this->addOption('USE INDEX', $index);
                $this->addFieldsIf('rev_page', $this->fld_ids);
                $this->addFieldsIf('rev_id', $this->fld_ids || $this->fld_flags);
                $this->addFieldsIf('page_latest', $this->fld_flags);