Faster retrieval of range blocks, faster lookup of blocked by name
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 23 Aug 2005 16:52:42 +0000 (16:52 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 23 Aug 2005 16:52:42 +0000 (16:52 +0000)
includes/Block.php
includes/SpecialIpblocklist.php

index ffd53d0..84b2475 100644 (file)
@@ -25,7 +25,7 @@ define ( 'EB_RANGE_ONLY', 4 );
 class Block
 {
        /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry;
-       /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate;
+       /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mByName;
 
        function Block( $address = '', $user = '', $by = 0, $reason = '',
                $timestamp = '' , $auto = 0, $expiry = '' )
@@ -43,6 +43,7 @@ class Block
                }
 
                $this->mForUpdate = false;
+               $this->mByName = false;
                $this->initialiseRange();
        }
 
@@ -55,8 +56,10 @@ class Block
 
        function clear()
        {
-               $mAddress = $mReason = $mTimestamp = '';
-               $mUser = $mBy = 0;
+               $this->mAddress = $this->mReason = $this->mTimestamp = '';
+               $this->mUser = $this->mBy = 0;
+               $this->mByName = false;
+
        }
 
        /**
@@ -149,6 +152,11 @@ class Block
                $this->mExpiry = $row->ipb_expiry ?
                        wfTimestamp(TS_MW,$row->ipb_expiry) :
                        $row->ipb_expiry;
+               if ( isset( $row->user_name ) ) {
+                       $this->mByName = $row->user_name;
+               } else {
+                       $this->mByName = false;
+               }
 
                $this->initialiseRange();
        }
@@ -191,14 +199,15 @@ class Block
                        $options = '';
                }
                if ( $flags & EB_RANGE_ONLY ) {
-                       $cond = " WHERE ipb_address LIKE '%/%'";
+                       $cond = " AND ipb_address LIKE '%/%'";
                } else {
                        $cond = '';
                }
 
-               $ipblocks = $db->tableName( 'ipblocks' );
+               extract( $db->tableNames( 'ipblocks', 'user' ) );
 
-               $sql = "SELECT * FROM $ipblocks $cond ORDER BY ipb_timestamp DESC $options";
+               $sql = "SELECT ipblocks.*,user_name FROM $ipblocks,$user " .
+                       "WHERE user_id=ipb_by $cond ORDER BY ipb_timestamp DESC $options";
                $res = $db->query( $sql, 'Block::enumBans' );
                $num_rows = $db->numRows( $res );
 
@@ -325,6 +334,14 @@ class Block
                return $this->mNetworkBits;
        }
 
+       function getByName()
+       {
+               if ( $this->mByName === false ) {
+                       $this->mByName = User::whoIs( $this->mBy );
+               }
+               return $this->mByName;
+       }
+
        function forUpdate( $x = NULL ) {
                return wfSetVar( $this->mForUpdate, $x );
        }
index 86008b2..5bcb9cc 100644 (file)
@@ -145,7 +145,7 @@ function wfAddRow( $block, $tag ) {
        # Hide addresses blocked by User::spreadBlocks, for privacy
        $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
 
-       $name = User::whoIs( $block->mBy );
+       $name = $block->getByName();
        $ulink = $sk->makeKnownLinkObj( Title::makeTitle( NS_USER, $name ), $name );
        $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );