summaryrefslogtreecommitdiff
path: root/includes/BacklinkCache.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
committerPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
commit9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch)
tree46d1a0dee7febef5c2d57a9f7b972be16a163b3d /includes/BacklinkCache.php
parent78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff)
update to MediaWiki 1.17.0
Diffstat (limited to 'includes/BacklinkCache.php')
-rw-r--r--includes/BacklinkCache.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/includes/BacklinkCache.php b/includes/BacklinkCache.php
index 53f92dd9..02b0f170 100644
--- a/includes/BacklinkCache.php
+++ b/includes/BacklinkCache.php
@@ -22,6 +22,14 @@ class BacklinkCache {
}
/**
+ * Serialization handler, diasallows to serialize the database to prevent
+ * failures after this class is deserialized from cache with dead DB connection.
+ */
+ function __sleep() {
+ return array( 'partitionCache', 'fullResultCache', 'title' );
+ }
+
+ /**
* Clear locally stored data
*/
function clear() {
@@ -41,6 +49,7 @@ class BacklinkCache {
if ( !isset( $this->db ) ) {
$this->db = wfGetDB( DB_SLAVE );
}
+
return $this->db;
}
@@ -60,14 +69,17 @@ class BacklinkCache {
// Partial range, not cached
wfDebug( __METHOD__ . ": from DB (uncacheable range)\n" );
$conds = $this->getConditions( $table );
+
// Use the from field in the condition rather than the joined page_id,
// because databases are stupid and don't necessarily propagate indexes.
if ( $startId ) {
$conds[] = "$fromField >= " . intval( $startId );
}
+
if ( $endId ) {
$conds[] = "$fromField <= " . intval( $endId );
}
+
$res = $this->getDB()->select(
array( $table, 'page' ),
array( 'page_namespace', 'page_title', 'page_id' ),
@@ -78,6 +90,7 @@ class BacklinkCache {
'ORDER BY' => $fromField
) );
$ta = TitleArray::newFromResult( $res );
+
wfProfileOut( __METHOD__ );
return $ta;
}
@@ -95,7 +108,9 @@ class BacklinkCache {
) );
$this->fullResultCache[$table] = $res;
}
+
$ta = TitleArray::newFromResult( $this->fullResultCache[$table] );
+
wfProfileOut( __METHOD__ );
return $ta;
}
@@ -150,6 +165,7 @@ class BacklinkCache {
default:
throw new MWException( "Invalid table \"$table\" in " . __CLASS__ );
}
+
return $conds;
}
@@ -167,6 +183,7 @@ class BacklinkCache {
}
$titleArray = $this->getLinks( $table );
+
return $titleArray->count();
}
@@ -193,29 +210,35 @@ class BacklinkCache {
if ( isset( $this->fullResultCache[$table] ) ) {
$cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
wfDebug( __METHOD__ . ": got from full result cache\n" );
+
return $cacheEntry['batches'];
}
// Try memcached
global $wgMemc;
+
$memcKey = wfMemcKey(
'backlinks',
md5( $this->title->getPrefixedDBkey() ),
$table,
$batchSize
);
+
$memcValue = $wgMemc->get( $memcKey );
if ( is_array( $memcValue ) ) {
$cacheEntry = $memcValue;
wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
+
return $cacheEntry['batches'];
}
+
// Fetch from database
$this->getLinks( $table );
$cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
// Save to memcached
$wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
+
wfDebug( __METHOD__ . ": got from database\n" );
return $cacheEntry['batches'];
}
@@ -254,6 +277,7 @@ class BacklinkCache {
$batches[] = array( $start, $end );
}
+
return array( 'numRows' => $numRows, 'batches' => $batches );
}
}