X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FBacklinkCache.php;h=02b0f170c5b01fac0eb656ff09a8570ce31c99d7;hb=304e80e20beb812da7a1128dbe2df621c627fc3d;hp=53f92dd95820bcd08a1aa1d5fcbd07ba7332ff2e;hpb=f8b1c4cfb7a9f55e94751ad89306f7712391c38e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/BacklinkCache.php b/includes/BacklinkCache.php index 53f92dd958..02b0f170c5 100644 --- a/includes/BacklinkCache.php +++ b/includes/BacklinkCache.php @@ -21,6 +21,14 @@ class BacklinkCache { $this->title = $title; } + /** + * 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 */ @@ -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 ); } }