r25140 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25139‎ | r25140 | r25141 >
Date:20:15, 25 August 2007
Author:aaron
Status:old
Tags:
Comment:
*Explicitly specify query
*Force the proper indexes. Filesorts where showing up on EXPLAIN for no reason. Uses indexes know.
*Remove number "10,000" that was still left.
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -146,13 +146,16 @@
147147 }
148148
149149 $dbr = wfGetDB( DB_SLAVE );
 150+
 151+ $ip_conds = $dbr->makeList( $this->getIpConds( $dbr, $ip, $xfor ), LIST_AND );
 152+ $cu_changes = $dbr->tableName( 'cu_changes' );
150153 # Limit added for browser limitations and to avoid time outs
151 - $ip_conds = $this->getIpConds( $dbr, $ip, $xfor );
152 - $res = $dbr->select( 'cu_changes', '*', $ip_conds, $fname,
153 - array( 'ORDER BY' => 'cuc_timestamp DESC', 'LIMIT' => 5000 ) );
154 - $ret = $dbr->resultObject( $res );
 154+ $index = $xfor ? 'cuc_xff_hex_time' : 'cuc_ip_hex_time';
 155+ $sql = "SELECT * FROM $cu_changes FORCE INDEX($index) WHERE $ip_conds
 156+ ORDER BY cuc_timestamp DESC LIMIT 5000";
155157
156 - if( !$dbr->numRows( $res ) ) {
 158+ $ret = $dbr->query( $sql, __METHOD__ );
 159+ if( !$dbr->numRows( $ret ) ) {
157160 $s = wfMsgHtml("checkuser-nomatch")."\n";
158161 } else {
159162 global $IP;
@@ -177,7 +180,7 @@
178181 }
179182
180183 $wgOut->addHTML( $s );
181 - $dbr->freeResult( $res );
 184+ $dbr->freeResult( $ret );
182185 }
183186
184187 /**
@@ -320,24 +323,27 @@
321324 {
322325 $wgOut->addHTML( '<p>'.wfMsgHtml('checkuser-log-fail').'</p>' );
323326 }
324 -
 327+
325328 $sk = $wgUser->getSkin();
326329
327 - $users_first = $users_last = $users_edits = $users_ids = array();
 330+ $dbr = wfGetDB( DB_SLAVE );
328331
329 - $dbr = wfGetDB( DB_SLAVE );
 332+ $ip_conds = $dbr->makeList( $this->getIpConds( $dbr, $ip, $xfor ), LIST_AND );
 333+ $cu_changes = $dbr->tableName( 'cu_changes' );
 334+ $index = $xfor ? 'cuc_xff_hex_time' : 'cuc_ip_hex_time';
330335 # Limit cap made to stop nasty timeouts
331 - $ip_conds = $this->getIpConds( $dbr, $ip, $xfor );
332 - $res = $dbr->select( 'cu_changes',
333 - array( 'cuc_user_text', 'cuc_timestamp', 'cuc_user', 'cuc_ip', 'cuc_agent', 'cuc_xff' ),
334 - $ip_conds,
335 - $fname,
336 - array( 'ORDER BY' => 'cuc_timestamp DESC', 'LIMIT' => 10000 ) );
 336+ $sql = "SELECT cuc_user_text, cuc_timestamp, cuc_user, cuc_ip, cuc_agent, cuc_xff
 337+ FROM $cu_changes FORCE INDEX($index) WHERE $ip_conds
 338+ ORDER BY cuc_timestamp DESC LIMIT 10000";
337339
338 - if( !$dbr->numRows( $res ) ) {
 340+ $ret = $dbr->query( $sql, __METHOD__ );
 341+
 342+ $users_first = $users_last = $users_edits = $users_ids = array();
 343+
 344+ if( !$dbr->numRows( $ret ) ) {
339345 $s = wfMsgHtml( "checkuser-nomatch" )."\n";
340346 } else {
341 - while( ($row = $dbr->fetchObject( $res ) ) != false ) {
 347+ while( ($row = $dbr->fetchObject( $ret ) ) != false ) {
342348 if( !array_key_exists( $row->cuc_user_text, $users_edits ) ) {
343349 $users_last[$row->cuc_user_text] = $row->cuc_timestamp;
344350 $users_edits[$row->cuc_user_text] = 0;
@@ -417,7 +423,7 @@
418424 }
419425
420426 $wgOut->addHTML( $s );
421 - $dbr->freeResult( $res );
 427+ $dbr->freeResult( $ret );
422428 }
423429
424430 /**
@@ -494,17 +500,21 @@
495501 $wgOut->addHTML( '<p>'.wfMsgHtml('checkuser-log-fail').'</p>' );
496502 }
497503 $dbr = wfGetDB( DB_SLAVE );
498 - # Limit cap made to stop nasty time outs
499 - $res = $dbr->select( 'cu_changes', array( 'cuc_ip', 'cuc_timestamp' ),
500 - array( 'cuc_user' => $user_id ),
501 - $fname,
502 - array( 'ORDER BY' => 'cuc_timestamp DESC', 'LIMIT' => 10,000 ) );
503 - if( !$dbr->numRows( $res ) ) {
 504+
 505+ $cu_changes = $dbr->tableName( 'cu_changes' );
 506+ # Limit cap made to stop nasty timeouts
 507+ $sql = "SELECT cuc_ip, cuc_timestamp
 508+ FROM $cu_changes FORCE INDEX(cuc_user_time) WHERE cuc_user = $user_id
 509+ ORDER BY cuc_timestamp DESC LIMIT 10000";
 510+
 511+ $ret = $dbr->query( $sql, __METHOD__ );
 512+
 513+ if( !$dbr->numRows( $ret ) ) {
504514 $s = wfMsgHtml("checkuser-nomatch")."\n";
505515 } else {
506516 $blockip = SpecialPage::getTitleFor( 'blockip' );
507517 $ips_edits=array();
508 - while( $row = $dbr->fetchObject( $res ) ) {
 518+ while( $row = $dbr->fetchObject( $ret ) ) {
509519 if( !array_key_exists( $row->cuc_ip, $ips_edits ) ) {
510520 $ips_edits[$row->cuc_ip]=0;
511521 $ips_last[$row->cuc_ip]=$row->cuc_timestamp;
@@ -546,6 +556,7 @@
547557 $s .= '</ul>';
548558 }
549559 $wgOut->addHTML( $s );
 560+ $dbr->freeResult( $ret );
550561 }
551562
552563 function showLog( $user ) {

Status & tagging log