* @see BacklinkCache::partitionResult()
*
* Cleared with BacklinkCache::clear()
+ * @var array[]
*/
protected $partitionCache = array();
*
* Initialized with BacklinkCache::getLinks()
* Cleared with BacklinkCache::clear()
+ * @var ResultWrapper[]
*/
protected $fullResultCache = array();
/**
* Set the Database object to use
*
- * @param DatabaseBase $db
+ * @param IDatabase $db
*/
public function setDB( $db ) {
$this->db = $db;
* @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 ) {
* @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
*/
/**
* 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] );
$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 );
}
// 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 );
}
}
* @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" );
return $this->partitionCache[$table][$batchSize]['batches'];
}
+ $cache = ObjectCache::getMainWANInstance();
$this->partitionCache[$table][$batchSize] = false;
$cacheEntry =& $this->partitionCache[$table][$batchSize];
);
// 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" );
}
// 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" );