Merge "Add option to expose original sha1 in thumb url"
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
index f702a22..6361463 100644 (file)
@@ -200,6 +200,7 @@ class LocalRepo extends FileRepo {
                } else {
                        $expiry = 86400; // has invalidation, 1 day
                }
+
                $cachedValue = $cache->get( $memcKey );
                if ( $cachedValue === ' ' || $cachedValue === '' ) {
                        // Does not exist
@@ -208,9 +209,11 @@ class LocalRepo extends FileRepo {
                        return Title::newFromText( $cachedValue, NS_FILE );
                } // else $cachedValue is false or null: cache miss
 
+               $opts = array( 'since' => $this->getSlaveDB()->trxTimestamp() );
+
                $id = $this->getArticleID( $title );
                if ( !$id ) {
-                       $cache->set( $memcKey, " ", $expiry );
+                       $cache->set( $memcKey, " ", $expiry, $opts );
 
                        return false;
                }
@@ -224,11 +227,11 @@ class LocalRepo extends FileRepo {
 
                if ( $row && $row->rd_namespace == NS_FILE ) {
                        $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
-                       $cache->set( $memcKey, $targetTitle->getDBkey(), $expiry );
+                       $cache->set( $memcKey, $targetTitle->getDBkey(), $expiry, $opts );
 
                        return $targetTitle;
                } else {
-                       $cache->set( $memcKey, '', $expiry );
+                       $cache->set( $memcKey, '', $expiry, $opts );
 
                        return false;
                }
@@ -248,12 +251,12 @@ class LocalRepo extends FileRepo {
                $dbr = $this->getSlaveDB();
                $id = $dbr->selectField(
                        'page', // Table
-                       'page_id', //Field
-                       array( //Conditions
+                       'page_id', // Field
+                       array( // Conditions
                                'page_namespace' => $title->getNamespace(),
                                'page_title' => $title->getDBkey(),
                        ),
-                       __METHOD__ //Function name
+                       __METHOD__ // Function name
                );
 
                return $id;
@@ -421,7 +424,7 @@ class LocalRepo extends FileRepo {
         */
        function findBySha1s( array $hashes ) {
                if ( !count( $hashes ) ) {
-                       return array(); //empty parameter
+                       return array(); // empty parameter
                }
 
                $dbr = $this->getSlaveDB();
@@ -518,15 +521,11 @@ class LocalRepo extends FileRepo {
         * @return void
         */
        function invalidateImageRedirect( Title $title ) {
-               $cache = ObjectCache::getMainWANInstance();
-
-               $memcKey = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) );
-               if ( $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.
-                       $cache->delete( $memcKey, 12 );
+               $key = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) );
+               if ( $key ) {
+                       $this->getMasterDB()->onTransactionPreCommitOrIdle( function() use ( $key ) {
+                               ObjectCache::getMainWANInstance()->delete( $key );
+                       } );
                }
        }