Page MenuHomePhabricator

block.patch

Authored By
bzimport
Nov 21 2014, 8:01 PM
Size
7 KB
Referenced Files
None
Subscribers
None

block.patch

? block.patch
Index: includes/BlockCache.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/BlockCache.php,v
retrieving revision 1.9
diff -c -r1.9 BlockCache.php
*** includes/BlockCache.php 22 Jan 2005 08:30:39 -0000 1.9
--- includes/BlockCache.php 24 Jan 2005 22:25:35 -0000
***************
*** 36,50 ****
/**
* Load the blocks from the database and save them to memcached
*/
! function loadFromDB() {
global $wgUseMemCached, $wgMemc;
$this->mData = array();
# Selecting FOR UPDATE is a convenient way to serialise the memcached and DB operations,
# which is necessary even though we don't update the DB
! if ( $wgUseMemCached ) {
Block::enumBlocks( 'wfBlockCacheInsert', '', EB_FOR_UPDATE );
! $wgMemc->set( $this->mMemcKey, $this->mData, 0 );
} else {
Block::enumBlocks( 'wfBlockCacheInsert', '' );
}
--- 36,51 ----
/**
* Load the blocks from the database and save them to memcached
+ * @param bool $bFromSlave Whether to load data from slaves or master
*/
! function loadFromDB( $bFromSlave = false ) {
global $wgUseMemCached, $wgMemc;
$this->mData = array();
# Selecting FOR UPDATE is a convenient way to serialise the memcached and DB operations,
# which is necessary even though we don't update the DB
! if ( !$bFromSlave ) {
Block::enumBlocks( 'wfBlockCacheInsert', '', EB_FOR_UPDATE );
! #$wgMemc->set( $this->mMemcKey, $this->mData, 0 );
} else {
Block::enumBlocks( 'wfBlockCacheInsert', '' );
}
***************
*** 53,70 ****
/**
* Load the cache from memcached or, if that's not possible, from the DB
*/
! function load() {
global $wgUseMemCached, $wgMemc;
if ( $this->mData === false) {
# Try memcached
if ( $wgUseMemCached ) {
$this->mData = $wgMemc->get( $this->mMemcKey );
}
if ( !is_array( $this->mData ) ) {
! $this->loadFromDB();
! }
}
}
--- 54,74 ----
/**
* Load the cache from memcached or, if that's not possible, from the DB
*/
! function load( $bFromSlave ) {
global $wgUseMemCached, $wgMemc;
if ( $this->mData === false) {
+ $this->loadFromDB( $bFromSlave );
+ /*
+ // Memcache disabled for performance issues.
# Try memcached
if ( $wgUseMemCached ) {
$this->mData = $wgMemc->get( $this->mMemcKey );
}
if ( !is_array( $this->mData ) ) {
! $this->loadFromDB( $bFromSlave );
! }*/
}
}
***************
*** 91,99 ****
* Find out if a given IP address is blocked
*
* @param String $ip IP address
*/
! function get( $ip ) {
! $this->load();
$ipint = ip2long( $ip );
$blocked = false;
--- 95,104 ----
* Find out if a given IP address is blocked
*
* @param String $ip IP address
+ * @param bool $bFromSlave True means to load check against slave, else check against master.
*/
! function get( $ip, $bFromSlave ) {
! $this->load( $bFromSlave );
$ipint = ip2long( $ip );
$blocked = false;
***************
*** 110,115 ****
--- 115,121 ----
$ip = Block::normaliseRange( $ip );
}
$block = new Block();
+ $block->forUpdate( $bFromSlave );
$block->load( $ip );
} else {
$block = false;
Index: includes/EditPage.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/EditPage.php,v
retrieving revision 1.142
diff -c -r1.142 EditPage.php
*** includes/EditPage.php 31 Dec 2004 14:53:56 -0000 1.142
--- includes/EditPage.php 24 Jan 2005 22:28:23 -0000
***************
*** 150,156 ****
$wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
return;
}
! if ( $wgUser->isBlocked() ) {
$this->blockedIPpage();
return;
}
--- 150,158 ----
$wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
return;
}
! if ( !$this->preview && $wgUser->isBlocked( !$this->save ) ) {
! # When previewing, don't check blocked state - will get caught at save time.
! # Also, check when starting edition is done against slave to improve performance.
$this->blockedIPpage();
return;
}
***************
*** 271,277 ****
# Error messages or other handling should be performed by the filter function
return;
}
! if ( $wgUser->isBlocked() ) {
$this->blockedIPpage();
return;
}
--- 273,280 ----
# Error messages or other handling should be performed by the filter function
return;
}
! if ( $wgUser->isBlocked( false ) ) {
! # Check block state against master, thus 'false'.
$this->blockedIPpage();
return;
}
Index: includes/User.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/User.php,v
retrieving revision 1.117
diff -c -r1.117 User.php
*** includes/User.php 23 Jan 2005 16:37:12 -0000 1.117
--- includes/User.php 24 Jan 2005 22:28:07 -0000
***************
*** 242,249 ****
/**
* Get blocking information
* @access private
*/
! function getBlockedStatus() {
global $wgIP, $wgBlockCache, $wgProxyList;
if ( -1 != $this->mBlockedby ) { return; }
--- 242,257 ----
/**
* Get blocking information
* @access private
+ * @param bool $bFromSlave Specify whether to check slave or master. To improve performance,
+ * non-critical checks are done against slaves. Check when actually saving should be done against
+ * master.
+ *
+ * Note that even if $bFromSlave is false, the check is done first against slave, then master.
+ * The logic is that if blocked on slave, we'll assume it's either blocked on master or
+ * just slightly outta sync and soon corrected - safer to block slightly more that less.
+ * And it's cheaper to check slave first, then master if needed, than master always.
*/
! function getBlockedStatus( $bFromSlave = false ) {
global $wgIP, $wgBlockCache, $wgProxyList;
if ( -1 != $this->mBlockedby ) { return; }
***************
*** 253,259 ****
# User blocking
if ( $this->mId ) {
$block = new Block();
! if ( $block->load( $wgIP , $this->mId ) ) {
$this->mBlockedby = $block->mBy;
$this->mBlockreason = $block->mReason;
}
--- 261,268 ----
# User blocking
if ( $this->mId ) {
$block = new Block();
! $block->forUpdate( $bFromSlave );
! if ( $block->load( $wgIP , $this->mId ) ) {
$this->mBlockedby = $block->mBy;
$this->mBlockreason = $block->mReason;
}
***************
*** 261,267 ****
# IP/range blocking
if ( !$this->mBlockedby ) {
! $block = $wgBlockCache->get( $wgIP );
if ( $block !== false ) {
$this->mBlockedby = $block->mBy;
$this->mBlockreason = $block->mReason;
--- 270,283 ----
# IP/range blocking
if ( !$this->mBlockedby ) {
! # Check first against slave, and optionally from master.
! $block = $wgBlockCache->get( $wgIP, true );
! if ( !block && !$bFromSlave )
! {
! # Not blocked: check against master, to make sure.
! $wgBlockCache->clearLocal( );
! $block = $wgBlockCache->get( $wgIP, false );
! }
if ( $block !== false ) {
$this->mBlockedby = $block->mBy;
$this->mBlockreason = $block->mReason;
***************
*** 281,288 ****
* Check if user is blocked
* @return bool True if blocked, false otherwise
*/
! function isBlocked() {
! $this->getBlockedStatus();
if ( 0 === $this->mBlockedby ) { return false; }
return true;
}
--- 297,304 ----
* Check if user is blocked
* @return bool True if blocked, false otherwise
*/
! function isBlocked( $bFromSlave = false ) {
! $this->getBlockedStatus( $bFromSlave );
if ( 0 === $this->mBlockedby ) { return false; }
return true;
}

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1301
Default Alt Text
block.patch (7 KB)

Event Timeline