summaryrefslogtreecommitdiff
path: root/includes/filerepo/LocalRepo.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/filerepo/LocalRepo.php')
-rw-r--r--includes/filerepo/LocalRepo.php42
1 files changed, 23 insertions, 19 deletions
diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php
index be11b233..9b62243b 100644
--- a/includes/filerepo/LocalRepo.php
+++ b/includes/filerepo/LocalRepo.php
@@ -47,7 +47,7 @@ class LocalRepo extends FileRepo {
} elseif ( isset( $row->oi_name ) ) {
return call_user_func( $this->oldFileFromRowFactory, $row, $this );
} else {
- throw new MWException( __METHOD__.': invalid row' );
+ throw new MWException( __METHOD__ . ': invalid row' );
}
}
@@ -171,13 +171,13 @@ class LocalRepo extends FileRepo {
if ( $cachedValue === ' ' || $cachedValue === '' ) {
// Does not exist
return false;
- } elseif ( strval( $cachedValue ) !== '' ) {
+ } elseif ( strval( $cachedValue ) !== '' && $cachedValue !== ' PURGED' ) {
return Title::newFromText( $cachedValue, NS_FILE );
} // else $cachedValue is false or null: cache miss
$id = $this->getArticleID( $title );
- if( !$id ) {
- $wgMemc->set( $memcKey, " ", $expiry );
+ if ( !$id ) {
+ $wgMemc->add( $memcKey, " ", $expiry );
return false;
}
$dbr = $this->getSlaveDB();
@@ -188,12 +188,12 @@ class LocalRepo extends FileRepo {
__METHOD__
);
- if( $row && $row->rd_namespace == NS_FILE ) {
+ if ( $row && $row->rd_namespace == NS_FILE ) {
$targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
- $wgMemc->set( $memcKey, $targetTitle->getDBkey(), $expiry );
+ $wgMemc->add( $memcKey, $targetTitle->getDBkey(), $expiry );
return $targetTitle;
} else {
- $wgMemc->set( $memcKey, '', $expiry );
+ $wgMemc->add( $memcKey, '', $expiry );
return false;
}
}
@@ -206,7 +206,7 @@ class LocalRepo extends FileRepo {
* @return bool|int|mixed
*/
protected function getArticleID( $title ) {
- if( !$title instanceof Title ) {
+ if ( !$title instanceof Title ) {
return 0;
}
$dbr = $this->getSlaveDB();
@@ -258,7 +258,7 @@ class LocalRepo extends FileRepo {
* @return array An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s( array $hashes ) {
- if( !count( $hashes ) ) {
+ if ( !count( $hashes ) ) {
return array(); //empty parameter
}
@@ -281,17 +281,17 @@ class LocalRepo extends FileRepo {
return $result;
}
- /**
- * Return an array of files where the name starts with $prefix.
- *
- * @param string $prefix The prefix to search for
- * @param int $limit The maximum amount of files to return
- * @return array
- */
+ /**
+ * Return an array of files where the name starts with $prefix.
+ *
+ * @param string $prefix The prefix to search for
+ * @param int $limit The maximum amount of files to return
+ * @return array
+ */
public function findFilesByPrefix( $prefix, $limit ) {
$selectOptions = array( 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) );
- // Query database
+ // Query database
$dbr = $this->getSlaveDB();
$res = $dbr->select(
'image',
@@ -306,7 +306,7 @@ class LocalRepo extends FileRepo {
foreach ( $res as $row ) {
$files[] = $this->newFileFromRow( $row );
}
- return $files;
+ return $files;
}
/**
@@ -347,7 +347,11 @@ class LocalRepo extends FileRepo {
global $wgMemc;
$memcKey = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) );
if ( $memcKey ) {
- $wgMemc->delete( $memcKey );
+ // Set a temporary value for the cache key, to ensure
+ // that this value stays purged long enough so that
+ // it isn't refreshed with a stale value due to a
+ // lagged slave.
+ $wgMemc->set( $memcKey, ' PURGED', 12 );
}
}
}