X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FBlockCache.php;h=c64adc1094d9a03636cb33db4685d120ef2ceedf;hb=97bfb998ee07677a208b0578a7cc67d6e2936849;hp=135d206d9becf430e8ca873d03e482c084c133ce;hpb=5583e646bc03ebfc2b24c23f2fa61dcecdb6f612;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/BlockCache.php b/includes/BlockCache.php index 135d206d9b..c64adc1094 100644 --- a/includes/BlockCache.php +++ b/includes/BlockCache.php @@ -1,55 +1,84 @@ mMemcKey = "$dbName:ipblocks"; + $this->mMemcKey = $dbName.':ipblocks'; if ( !$deferLoad ) { $this->load(); } } - function load() - { + /** + * 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', '' ); + } + } + + /** + * Load the cache from memcached or, if that's not possible, from the DB + */ + function load( $bFromSlave ) { global $wgUseMemCached, $wgMemc; if ( $this->mData === false) { - $saveMemc = false; + $this->loadFromDB( $bFromSlave ); +/* + // Memcache disabled for performance issues. # Try memcached if ( $wgUseMemCached ) { $this->mData = $wgMemc->get( $this->mMemcKey ); - if ( !$this->mData ) { - $saveMemc = true; - } } if ( !is_array( $this->mData ) ) { - # Load from DB - $this->mData = array(); - Block::enumBlocks( "wfBlockCacheInsert", "" ); # Calls $this->insert() - } - - if ( $saveMemc ) { - $wgMemc->set( $this->mMemcKey, $this->mData, 0 ); - } + $this->loadFromDB( $bFromSlave ); + }*/ } } - function insert( &$block ) - { + /** + * Add a block to the cache + * + * @param Object &$block Reference to a "Block" object. + */ + function insert( &$block ) { if ( $block->mUser == 0 ) { $nb = $block->getNetworkBits(); $ipint = $block->getIntegerAddr(); @@ -62,10 +91,15 @@ class BlockCache $this->mData[$nb][$index] = 1; } } - - function get( $ip ) - { - $this->load(); + + /** + * 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; @@ -78,10 +112,11 @@ class BlockCache if ( $blocked ) { # Clear low order bits if ( $networkBits != 32 ) { - $ip .= "/$networkBits"; + $ip .= '/'.$networkBits; $ip = Block::normaliseRange( $ip ); } $block = new Block(); + $block->forUpdate( $bFromSlave ); $block->load( $ip ); } else { $block = false; @@ -90,24 +125,22 @@ class BlockCache return $block; } - function clear() - { - global $wgUseMemCached, $wgMemc; - - $this->mData = false; - if ( $wgUseMemCached ) { - $wgMemc->delete( $this->mMemcKey ); - } - } - - function clearLocal() - { + /** + * Clear the local cache + * There was once a clear() to clear memcached too, but I deleted it + */ + function clearLocal() { $this->mData = false; } } -function wfBlockCacheInsert( $block, $tag ) -{ +/** + * Add a block to the global $wgBlockCache + * + * @param Object $block A "Block"-object + * @param Any $tag unused + */ +function wfBlockCacheInsert( $block, $tag ) { global $wgBlockCache; $wgBlockCache->insert( $block ); }