* Fixed a bug where moving a page would cause the following SQL error when
[lhc/web/wiklou.git] / includes / BlockCache.php
index 9f099b2..c64adc1 100644 (file)
@@ -1,12 +1,26 @@
 <?php
+/**
+ * Contain the blockcache class
+ * @package MediaWiki
+ * @package Cache
+ */
 
-# Object for fast lookup of IP blocks
-# Represents a memcached value, and in some sense, the entire ipblocks table
-
+/**
+ * Object for fast lookup of IP blocks
+ * Represents a memcached value, and in some sense, the entire ipblocks table
+ * @package MediaWiki
+ */
 class BlockCache
 {
        var $mData = false, $mMemcKey;
 
+       /**
+        * Constructor
+        * Create a new BlockCache object
+        *
+        * @param Boolean $deferLoad   specifies whether to immediately load the data from memcached.
+        * @param String $dbName       specifies the memcached dbName prefix to be used. Defaults to $wgDBname.
+        */
        function BlockCache( $deferLoad = false, $dbName = '' ) {
                global $wgDBname;
 
@@ -21,37 +35,49 @@ class BlockCache
                }
        }
 
-       # Load the blocks from the database and save them to memcached
-       function loadFromDB() {
+       /**
+        * 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 ( $wgUseMemCached ) {
+               if ( !$bFromSlave ) {
                        Block::enumBlocks( 'wfBlockCacheInsert', '', EB_FOR_UPDATE );
-                       $wgMemc->set( $this->mMemcKey, $this->mData, 0 );
+                       #$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() {
+       /**
+        * 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();
-                       }
+                               $this->loadFromDB( $bFromSlave );
+                       }*/
                }
        }
 
-       # Add a block to the cache
+       /**
+        * Add a block to the cache
+        *
+        * @param Object &$block   Reference to a "Block" object.
+        */
        function insert( &$block ) {
                if ( $block->mUser == 0 ) {
                        $nb = $block->getNetworkBits();
@@ -66,9 +92,14 @@ class BlockCache
                }
        }
        
-       # Find out if a given IP address is blocked
-       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;
 
@@ -85,6 +116,7 @@ class BlockCache
                                $ip = Block::normaliseRange( $ip );
                        }
                        $block = new Block();
+                       $block->forUpdate( $bFromSlave );
                        $block->load( $ip );
                } else {
                        $block = false;
@@ -93,13 +125,21 @@ class BlockCache
                return $block;
        }
 
-       # Clear the local cache
-       # There was once a clear() to clear memcached too, but I deleted it
+       /**
+        * Clear the local cache
+        * There was once a clear() to clear memcached too, but I deleted it
+        */
        function clearLocal() {
                $this->mData = false;
        }
 }
 
+/**
+ * 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 );