r40688 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40687‎ | r40688 | r40689 >
Date:00:33, 10 September 2008
Author:aaron
Status:old
Tags:
Comment:
* Bump timestamp sort limit for "user edits"
* Add limit message
* Fix "user edits" row count estimate usage
* Fix "get users" limit usage
* Add more timeout sets for sites with low limits
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.i18n.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -275,21 +275,30 @@
276276 $sql = "SELECT cuc_ip,cuc_ip_hex, COUNT(*) AS count,
277277 MIN(cuc_timestamp) AS first, MAX(cuc_timestamp) AS last
278278 FROM $cu_changes $use_index WHERE cuc_user = $user_id AND $time_conds
279 - GROUP BY cuc_ip,cuc_ip_hex ORDER BY last DESC LIMIT 5000";
 279+ GROUP BY cuc_ip,cuc_ip_hex ORDER BY last DESC LIMIT 5001";
280280
281281 $ret = $dbr->query( $sql, __METHOD__ );
282 -
283282 if( !$dbr->numRows( $ret ) ) {
284283 $s = wfMsgHtml("checkuser-nomatch")."\n";
285284 } else {
286285 $blockip = SpecialPage::getTitleFor( 'blockip' );
287286 $ips_edits = array();
 287+ $counter = 0;
288288 while( $row = $dbr->fetchObject($ret) ) {
 289+ if( $counter >= 5000 ) {
 290+ $wgOut->addHTML( wfMsgExt('checkuser-limited',array('parse')) );
 291+ break;
 292+ }
289293 $ips_edits[$row->cuc_ip] = $row->count;
290294 $ips_first[$row->cuc_ip] = $row->first;
291295 $ips_last[$row->cuc_ip] = $row->last;
292296 $ips_hex[$row->cuc_ip] = $row->cuc_ip_hex;
 297+ ++$counter;
293298 }
 299+ // Count pinging might take some time...make sure it is there
 300+ wfSuppressWarnings();
 301+ set_time_limit(60);
 302+ wfRestoreWarnings();
294303
295304 $logs = SpecialPage::getTitleFor( 'Log' );
296305 $blocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
@@ -388,7 +397,7 @@
389398 # Check how many rows will need sorting ahead of time to see if this is too big.
390399 # Also, if we only show 5000, too many will be ignored as well.
391400 $index = $xfor ? 'cuc_xff_hex_time' : 'cuc_ip_hex_time';
392 - if( strpos($ip,'/') !==false ) {
 401+ if( strpos($ip,'/') !== false ) {
393402 # Quick index check only OK if no time constraint
394403 if( $period ) {
395404 $rangecount = $dbr->selectField( 'cu_changes', 'COUNT(*)',
@@ -406,6 +415,7 @@
407416 set_time_limit(60);
408417 wfRestoreWarnings();
409418 }
 419+ $counter = 0;
410420 # See what is best to do after testing the waters...
411421 if( isset($rangecount) && $rangecount > 5000 ) {
412422 $use_index = $dbr->useIndexClause( $index );
@@ -413,12 +423,16 @@
414424 MIN(cuc_timestamp) AS first, MAX(cuc_timestamp) AS last
415425 FROM $cu_changes $use_index
416426 WHERE $ip_conds AND $time_conds
417 - GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 5000";
 427+ GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 5001";
418428 $ret = $dbr->query( $sql, __METHOD__ );
419429 # List out each IP that has edits
420 - $s = '<h5>' . wfMsg('checkuser-too-many') . '</h5>';
 430+ $s = wfMsgExt('checkuser-too-many',array('parse'));
421431 $s .= '<ol>';
422432 while( $row = $ret->fetchObject() ) {
 433+ if( $counter >= 5000 ) {
 434+ $wgOut->addHTML( wfMsgExt('checkuser-limited',array('parse')) );
 435+ break;
 436+ }
423437 # Convert the IP hexes into normal form
424438 if( strpos($row->cuc_ip_hex,'v6-') !==false ) {
425439 $ip = substr( $row->cuc_ip_hex, 3 );
@@ -436,6 +450,7 @@
437451 ' -- ' . $wgLang->timeanddate( $row->last, true ) . ') ';
438452 }
439453 $s .= " [<strong>" . $row->count . "</strong>]</li>\n";
 454+ ++$counter;
440455 }
441456 $s .= '</ol>';
442457 $dbr->freeResult( $ret );
@@ -445,14 +460,13 @@
446461 } else if( isset($rangecount) && !$rangecount ) {
447462 $s = wfMsgHtml("checkuser-nomatch")."\n";
448463 $wgOut->addHTML( $s );
449 -
450464 return;
451465 }
452466 # OK, do the real query...
453467 $use_index = $dbr->useIndexClause( $index );
454468 $sql = "SELECT cuc_namespace,cuc_title,cuc_user,cuc_user_text,cuc_comment,cuc_actiontext,
455469 cuc_timestamp,cuc_minor,cuc_page_id,cuc_type,cuc_this_oldid,cuc_last_oldid,cuc_ip,cuc_xff,cuc_agent
456 - FROM $cu_changes $use_index WHERE $ip_conds AND $time_conds ORDER BY cuc_timestamp DESC LIMIT 5000";
 470+ FROM $cu_changes $use_index WHERE $ip_conds AND $time_conds ORDER BY cuc_timestamp DESC LIMIT 5001";
457471 $ret = $dbr->query( $sql, __METHOD__ );
458472
459473 if( !$dbr->numRows( $ret ) ) {
@@ -473,7 +487,12 @@
474488 # List out the edits
475489 $s = '<div id="checkuserresults">';
476490 while( $row = $ret->fetchObject() ) {
 491+ if( $counter >= 5000 ) {
 492+ $wgOut->addHTML( wfMsgExt('checkuser-limited',array('parse')) );
 493+ break;
 494+ }
477495 $s .= $this->CUChangesLine( $row, $reason );
 496+ ++$counter;
478497 }
479498 $s .= '</ul></div>';
480499 $dbr->freeResult( $ret );
@@ -524,14 +543,22 @@
525544 # Ordered in descent by timestamp. Causes large filesorts if there are many edits.
526545 # Check how many rows will need sorting ahead of time to see if this is too big.
527546 # If it is, sort by IP,time to avoid the filesort.
528 - $count = $dbr->estimateRowCount( 'cu_changes', '*',
529 - array( $user_cond, $time_conds ),
530 - __METHOD__,
531 - array( 'USE INDEX' => 'cuc_user_ip_time' ) );
 547+ if( $period ) {
 548+ $count = $dbr->selectField( 'cu_changes', 'COUNT(*)',
 549+ array( $user_cond, $time_conds ),
 550+ __METHOD__,
 551+ array( 'USE INDEX' => 'cuc_user_ip_time' ) );
 552+ } else {
 553+ $count = $dbr->estimateRowCount( 'cu_changes', '*',
 554+ array( $user_cond, $time_conds ),
 555+ __METHOD__,
 556+ array( 'USE INDEX' => 'cuc_user_ip_time' ) );
 557+ }
532558 # Cache common messages
533559 $this->preCacheMessages();
534560 # See what is best to do after testing the waters...
535 - if( $count > 3000 ) {
 561+ if( $count > 5000 ) {
 562+ $wgOut->addHTML( wfMsgExt('checkuser-limited',array('parse')) );
536563 $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
537564 $sql = "SELECT * FROM $cu_changes $use_index
538565 WHERE $user_cond AND $time_conds
@@ -565,6 +592,10 @@
566593 $wgOut->addHTML( $s );
567594 return;
568595 }
 596+ // Sorting might take some time...make sure it is there
 597+ wfSuppressWarnings();
 598+ set_time_limit(60);
 599+ wfRestoreWarnings();
569600 # OK, do the real query...
570601 $use_index = $dbr->useIndexClause( 'cuc_user_ip_time' );
571602 $sql = "SELECT * FROM $cu_changes $use_index
@@ -652,12 +683,17 @@
653684 $sql = "SELECT cuc_ip_hex, COUNT(*) AS count,
654685 MIN(cuc_timestamp) AS first, MAX(cuc_timestamp) AS last
655686 FROM $cu_changes $use_index WHERE $ip_conds AND $time_conds
656 - GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 5000";
 687+ GROUP BY cuc_ip_hex ORDER BY cuc_ip_hex LIMIT 5001";
657688 $ret = $dbr->query( $sql, __METHOD__ );
658689 # List out each IP that has edits
659690 $s = '<h5>' . wfMsg('checkuser-too-many') . '</h5>';
660691 $s .= '<ol>';
 692+ $counter = 0;
661693 while( $row = $ret->fetchObject() ) {
 694+ if( $counter >= 5000 ) {
 695+ $wgOut->addHTML( wfMsgExt('checkuser-limited',array('parse')) );
 696+ break;
 697+ }
662698 # Convert the IP hexes into normal form
663699 if( strpos($row->cuc_ip_hex,'v6-') !==false ) {
664700 $ip = substr( $row->cuc_ip_hex, 3 );
@@ -675,6 +711,7 @@
676712 ' -- ' . $wgLang->timeanddate( $row->last, true ) . ') ';
677713 }
678714 $s .= " [<strong>" . $row->count . "</strong>]</li>\n";
 715+ ++$counter;
679716 }
680717 $s .= '</ol>';
681718 $dbr->freeResult( $ret );
@@ -692,7 +729,7 @@
693730 $use_index = $dbr->useIndexClause( $index );
694731 $sql = "SELECT cuc_user_text, cuc_timestamp, cuc_user, cuc_ip, cuc_agent, cuc_xff
695732 FROM $cu_changes $use_index WHERE $ip_conds AND $time_conds
696 - ORDER BY cuc_timestamp DESC LIMIT 5000";
 733+ ORDER BY cuc_timestamp DESC LIMIT 10000";
697734 $ret = $dbr->query( $sql, __METHOD__ );
698735
699736 $users_first = $users_last = $users_edits = $users_ids = array();
Index: trunk/extensions/CheckUser/CheckUser.i18n.php
@@ -62,6 +62,8 @@
6363 'checkuser-ipeditcount' => '~$1 from all users',
6464 'checkuser-log-subpage' => 'Log',
6565 'checkuser-log-return' => 'Return to CheckUser main form',
 66+
 67+ 'checkuser-limited' => '\'\'\'These results have been truncated for performance reasons.\'\'\'',
6668
6769 'checkuser-log-userips' => '$1 got IPs for $2',
6870 'checkuser-log-ipedits' => '$1 got edits for $2',