Merge "Use ImportStringSource for simple import sources"
[lhc/web/wiklou.git] / includes / cache / BacklinkCache.php
index 10b4fb0..3ba4f61 100644 (file)
@@ -133,7 +133,7 @@ class BacklinkCache {
        /**
         * Set the Database object to use
         *
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         */
        public function setDB( $db ) {
                $this->db = $db;
@@ -157,7 +157,7 @@ class BacklinkCache {
         * @param string $table
         * @param int|bool $startId
         * @param int|bool $endId
-        * @param int|INF $max
+        * @param int $max
         * @return TitleArrayFromResult
         */
        public function getLinks( $table, $startId = false, $endId = false, $max = INF ) {
@@ -169,7 +169,7 @@ class BacklinkCache {
         * @param string $table
         * @param int|bool $startId
         * @param int|bool $endId
-        * @param int|INF $max
+        * @param int $max
         * @param string $select 'all' or 'ids'
         * @return ResultWrapper
         */
@@ -319,12 +319,13 @@ class BacklinkCache {
        /**
         * Get the approximate number of backlinks
         * @param string $table
-        * @param int|INF $max Only count up to this many backlinks
+        * @param int $max Only count up to this many backlinks
         * @return int
         */
        public function getNumLinks( $table, $max = INF ) {
-               global $wgMemc, $wgUpdateRowsPerJob;
+               global $wgUpdateRowsPerJob;
 
+               $cache = ObjectCache::getMainWANInstance();
                // 1) try partition cache ...
                if ( isset( $this->partitionCache[$table] ) ) {
                        $entry = reset( $this->partitionCache[$table] );
@@ -340,7 +341,7 @@ class BacklinkCache {
                $memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
 
                // 3) ... fallback to memcached ...
-               $count = $wgMemc->get( $memcKey );
+               $count = $cache->get( $memcKey );
                if ( $count ) {
                        return min( $max, $count );
                }
@@ -355,7 +356,7 @@ class BacklinkCache {
                        // Fetch the full title info, since the caller will likely need it next
                        $count = $this->getLinks( $table, false, false, $max )->count();
                        if ( $count < $max ) { // full count
-                               $wgMemc->set( $memcKey, $count, self::CACHE_EXPIRY );
+                               $cache->set( $memcKey, $count, self::CACHE_EXPIRY );
                        }
                }
 
@@ -372,8 +373,6 @@ class BacklinkCache {
         * @return array
         */
        public function partition( $table, $batchSize ) {
-               global $wgMemc;
-
                // 1) try partition cache ...
                if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
                        wfDebug( __METHOD__ . ": got from partition cache\n" );
@@ -381,6 +380,7 @@ class BacklinkCache {
                        return $this->partitionCache[$table][$batchSize]['batches'];
                }
 
+               $cache = ObjectCache::getMainWANInstance();
                $this->partitionCache[$table][$batchSize] = false;
                $cacheEntry =& $this->partitionCache[$table][$batchSize];
 
@@ -400,7 +400,7 @@ class BacklinkCache {
                );
 
                // 3) ... fallback to memcached ...
-               $memcValue = $wgMemc->get( $memcKey );
+               $memcValue = $cache->get( $memcKey );
                if ( is_array( $memcValue ) ) {
                        $cacheEntry = $memcValue;
                        wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
@@ -432,11 +432,11 @@ class BacklinkCache {
                }
 
                // Save partitions to memcached
-               $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
+               $cache->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
 
                // Save backlink count to memcached
                $memcKey = wfMemcKey( 'numbacklinks', md5( $this->title->getPrefixedDBkey() ), $table );
-               $wgMemc->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
+               $cache->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
 
                wfDebug( __METHOD__ . ": got from database\n" );