http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88681

Revision: 88681
Author:   reedy
Date:     2011-05-23 20:38:02 +0000 (Mon, 23 May 2011)
Log Message:
-----------
More RAW SQL rewriting

Modified Paths:
--------------
    trunk/extensions/CheckUser/CheckUser_body.php

Modified: trunk/extensions/CheckUser/CheckUser_body.php
===================================================================
--- trunk/extensions/CheckUser/CheckUser_body.php       2011-05-23 20:26:21 UTC 
(rev 88680)
+++ trunk/extensions/CheckUser/CheckUser_body.php       2011-05-23 20:38:02 UTC 
(rev 88681)
@@ -24,7 +24,6 @@
                global $wgRequest, $wgOut, $wgUser, $wgContLang;
 
                $this->setHeaders();
-               $this->sk = $wgUser->getSkin();
 
                // This is horribly shitty.
                // Lacking formal aliases, it's tough to ensure we have 
compatibility.
@@ -587,13 +586,17 @@
                $counter = 0;
                # See what is best to do after testing the waters...
                if ( isset( $rangecount ) && $rangecount > 5000 ) {
-                       $use_index = $dbr->useIndexClause( $index );
-                       $sql = "SELECT cuc_ip_hex, COUNT(*) AS count,
-                               MIN(cuc_timestamp) AS first, MAX(cuc_timestamp) 
AS last
-                               FROM $cu_changes $use_index
-                               WHERE $ip_conds AND $time_conds
-                               GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 
5001";
-                       $ret = $dbr->query( $sql, __METHOD__ );
+                       $ret = $dbr->select( 'cu_changes',
+                               array( 'cuc_ip_hex', 'COUNT(*) AS count', 
'MIN(cuc_timestamp) AS first', 'MAX(cuc_timestamp AS last' ),
+                               array( $ip_conds, $time_conds ),
+                               __METHOD___,
+                               array(
+                                       'GROUP BY' => 'cuc_ip_hex',
+                                       'ORDER BY' => 'cuc_ip_hex',
+                                       'LIMIT' => 5001,
+                                       'USE INDEX' => $index,
+                               )
+                       );
                        # List out each IP that has edits
                        $s = wfMsgExt( 'checkuser-too-many', array( 'parse' ) );
                        $s .= '<ol>';
@@ -631,13 +634,24 @@
                        $wgOut->addHTML( $s );
                        return;
                }
+
                # OK, do the real query...
-               $use_index = $dbr->useIndexClause( $index );
-               $sql = "SELECT 
cuc_namespace,cuc_title,cuc_user,cuc_user_text,cuc_comment,cuc_actiontext,
-                       
cuc_timestamp,cuc_minor,cuc_page_id,cuc_type,cuc_this_oldid,cuc_last_oldid,cuc_ip,cuc_xff,cuc_agent
-                       FROM $cu_changes $use_index WHERE $ip_conds AND 
$time_conds ORDER BY cuc_timestamp DESC LIMIT 5001";
-               $ret = $dbr->query( $sql, __METHOD__ );
 
+               $ret = $dbr->select(
+                       'cu_changes',
+                       array( 'cuc_namespace','cuc_title', 'cuc_user', 
'cuc_user_text', 'cuc_comment', 'cuc_actiontext',
+                       'cuc_timestamp', 'cuc_minor', 'cuc_page_id', 
'cuc_type', 'cuc_this_oldid',
+                       'cuc_last_oldid', 'cuc_ip', 'cuc_xff','cuc_agent'
+                       ),
+                       array( $ip_conds, $time_conds ),
+                       __METHOD__,
+                       array(
+                               'ORDER BY' => 'cuc_timestamp DESC',
+                               'LIMIT' => 5001,
+                               'USE INDEX' => $index,
+                       )
+               );
+
                if ( !$dbr->numRows( $ret ) ) {
                        $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
                } else {
@@ -706,7 +720,7 @@
                $dbr = wfGetDB( DB_SLAVE );
                $user_cond = "cuc_user = '$user_id'";
                $time_conds = $this->getTimeConds( $period );
-               $cu_changes = $dbr->tableName( 'cu_changes' );
+               $cu_changes = $dbr->tableName( '' );
                # Ordered in descent by timestamp. Causes large filesorts if 
there are many edits.
                # Check how many rows will need sorting ahead of time to see if 
this is too big.
                # If it is, sort by IP,time to avoid the filesort.
@@ -726,11 +740,18 @@
                # See what is best to do after testing the waters...
                if ( $count > 5000 ) {
                        $wgOut->addHTML( wfMsgExt( 'checkuser-limited', array( 
'parse' ) ) );
-                       $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
-                       $sql = "SELECT * FROM $cu_changes $use_index
-                               WHERE $user_cond AND $time_conds
-                               ORDER BY cuc_ip ASC, cuc_timestamp DESC LIMIT 
5000";
-                       $ret = $dbr->query( $sql, __METHOD__ );
+
+                       $ret = $dbr->select(
+                               'cu_changes',
+                               '*',
+                               array( $user_cond, $time_conds ),
+                               __METHOD__,
+                               array(
+                                       'ORDER BY' => 'cuc_ip ASC, 
cuc_timestamp DESC',
+                                       'LIMIT' => 5000,
+                                       'USE INDEX' => 'cuc_user_ip_time'
+                               )
+                       );
                        # Try to optimize this query
                        $lb = new LinkBatch;
                        foreach ( $ret as $row ) {
@@ -762,12 +783,20 @@
                wfSuppressWarnings();
                set_time_limit( 60 );
                wfRestoreWarnings();
+
                # OK, do the real query...
-               $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
-               $sql = "SELECT * FROM $cu_changes $use_index
-                       WHERE $user_cond AND $time_conds ORDER BY cuc_timestamp 
DESC LIMIT 5000";
-               $ret = $dbr->query( $sql, __METHOD__ );
 
+               $ret = $dbr->select(
+                       'cu_changes',
+                       '*',
+                       array( $user_cond, $time_conds ),
+                       __METHOD__,
+                       array(
+                               'ORDER BY' => 'cuc_timestamp DESC',
+                               'LIMIT' => 5000,
+                               'USE INDEX' => 'cuc_user_ip_time'
+                       )
+               );
                if ( !$dbr->numRows( $ret ) ) {
                        $s = $this->noMatchesMessage( $user ) . "\n";
                } else {


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

Reply via email to