r88681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88680‎ | r88681 | r88682 >
Date:20:38, 23 May 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
More RAW SQL rewriting
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -24,7 +24,6 @@
2525 global $wgRequest, $wgOut, $wgUser, $wgContLang;
2626
2727 $this->setHeaders();
28 - $this->sk = $wgUser->getSkin();
2928
3029 // This is horribly shitty.
3130 // Lacking formal aliases, it's tough to ensure we have compatibility.
@@ -587,13 +586,17 @@
588587 $counter = 0;
589588 # See what is best to do after testing the waters...
590589 if ( isset( $rangecount ) && $rangecount > 5000 ) {
591 - $use_index = $dbr->useIndexClause( $index );
592 - $sql = "SELECT cuc_ip_hex, COUNT(*) AS count,
593 - MIN(cuc_timestamp) AS first, MAX(cuc_timestamp) AS last
594 - FROM $cu_changes $use_index
595 - WHERE $ip_conds AND $time_conds
596 - GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 5001";
597 - $ret = $dbr->query( $sql, __METHOD__ );
 590+ $ret = $dbr->select( 'cu_changes',
 591+ array( 'cuc_ip_hex', 'COUNT(*) AS count', 'MIN(cuc_timestamp) AS first', 'MAX(cuc_timestamp AS last' ),
 592+ array( $ip_conds, $time_conds ),
 593+ __METHOD___,
 594+ array(
 595+ 'GROUP BY' => 'cuc_ip_hex',
 596+ 'ORDER BY' => 'cuc_ip_hex',
 597+ 'LIMIT' => 5001,
 598+ 'USE INDEX' => $index,
 599+ )
 600+ );
598601 # List out each IP that has edits
599602 $s = wfMsgExt( 'checkuser-too-many', array( 'parse' ) );
600603 $s .= '<ol>';
@@ -631,13 +634,24 @@
632635 $wgOut->addHTML( $s );
633636 return;
634637 }
 638+
635639 # OK, do the real query...
636 - $use_index = $dbr->useIndexClause( $index );
637 - $sql = "SELECT cuc_namespace,cuc_title,cuc_user,cuc_user_text,cuc_comment,cuc_actiontext,
638 - cuc_timestamp,cuc_minor,cuc_page_id,cuc_type,cuc_this_oldid,cuc_last_oldid,cuc_ip,cuc_xff,cuc_agent
639 - FROM $cu_changes $use_index WHERE $ip_conds AND $time_conds ORDER BY cuc_timestamp DESC LIMIT 5001";
640 - $ret = $dbr->query( $sql, __METHOD__ );
641640
 641+ $ret = $dbr->select(
 642+ 'cu_changes',
 643+ array( 'cuc_namespace','cuc_title', 'cuc_user', 'cuc_user_text', 'cuc_comment', 'cuc_actiontext',
 644+ 'cuc_timestamp', 'cuc_minor', 'cuc_page_id', 'cuc_type', 'cuc_this_oldid',
 645+ 'cuc_last_oldid', 'cuc_ip', 'cuc_xff','cuc_agent'
 646+ ),
 647+ array( $ip_conds, $time_conds ),
 648+ __METHOD__,
 649+ array(
 650+ 'ORDER BY' => 'cuc_timestamp DESC',
 651+ 'LIMIT' => 5001,
 652+ 'USE INDEX' => $index,
 653+ )
 654+ );
 655+
642656 if ( !$dbr->numRows( $ret ) ) {
643657 $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
644658 } else {
@@ -706,7 +720,7 @@
707721 $dbr = wfGetDB( DB_SLAVE );
708722 $user_cond = "cuc_user = '$user_id'";
709723 $time_conds = $this->getTimeConds( $period );
710 - $cu_changes = $dbr->tableName( 'cu_changes' );
 724+ $cu_changes = $dbr->tableName( '' );
711725 # Ordered in descent by timestamp. Causes large filesorts if there are many edits.
712726 # Check how many rows will need sorting ahead of time to see if this is too big.
713727 # If it is, sort by IP,time to avoid the filesort.
@@ -726,11 +740,18 @@
727741 # See what is best to do after testing the waters...
728742 if ( $count > 5000 ) {
729743 $wgOut->addHTML( wfMsgExt( 'checkuser-limited', array( 'parse' ) ) );
730 - $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
731 - $sql = "SELECT * FROM $cu_changes $use_index
732 - WHERE $user_cond AND $time_conds
733 - ORDER BY cuc_ip ASC, cuc_timestamp DESC LIMIT 5000";
734 - $ret = $dbr->query( $sql, __METHOD__ );
 744+
 745+ $ret = $dbr->select(
 746+ 'cu_changes',
 747+ '*',
 748+ array( $user_cond, $time_conds ),
 749+ __METHOD__,
 750+ array(
 751+ 'ORDER BY' => 'cuc_ip ASC, cuc_timestamp DESC',
 752+ 'LIMIT' => 5000,
 753+ 'USE INDEX' => 'cuc_user_ip_time'
 754+ )
 755+ );
735756 # Try to optimize this query
736757 $lb = new LinkBatch;
737758 foreach ( $ret as $row ) {
@@ -762,12 +783,20 @@
763784 wfSuppressWarnings();
764785 set_time_limit( 60 );
765786 wfRestoreWarnings();
 787+
766788 # OK, do the real query...
767 - $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
768 - $sql = "SELECT * FROM $cu_changes $use_index
769 - WHERE $user_cond AND $time_conds ORDER BY cuc_timestamp DESC LIMIT 5000";
770 - $ret = $dbr->query( $sql, __METHOD__ );
771789
 790+ $ret = $dbr->select(
 791+ 'cu_changes',
 792+ '*',
 793+ array( $user_cond, $time_conds ),
 794+ __METHOD__,
 795+ array(
 796+ 'ORDER BY' => 'cuc_timestamp DESC',
 797+ 'LIMIT' => 5000,
 798+ 'USE INDEX' => 'cuc_user_ip_time'
 799+ )
 800+ );
772801 if ( !$dbr->numRows( $ret ) ) {
773802 $s = $this->noMatchesMessage( $user ) . "\n";
774803 } else {

Comments

#Comment by Brion VIBBER (talk | contribs)   22:51, 23 May 2011

Regression in this revision...

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:

SELECT cu_ip,cu_ip_hex,MIN(cuc_timestamp) AS first,MAX(cuc_timestamp) AS last FROM `cu_changes` FORCE INDEX (cuc_user_ip_time) WHERE cuc_user = '1' AND (1 = 1) GROUP BY cuc_ip,cuc_ip_hex ORDER BY last DESC LIMIT 5001

from within function "CheckUser::doUserIPsRequest". Database returned error "1054: Unknown column 'cu_ip' in 'field list' (localhost)".


#Comment by Brion VIBBER (talk | contribs)   22:56, 23 May 2011

Ok the above belongs on r88678 ...

Status & tagging log