More rigorous clearing of image redirect cache
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 7 Aug 2013 20:26:52 +0000 (17:26 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 7 Aug 2013 20:30:58 +0000 (17:30 -0300)
Instead of deleting the cache key, set a temporary
value, so that the key stays "deleted" long enough
so that replag won't cause the key to be repopulated with
an incorrect value from a slave db.

Bug: 52200
Change-Id: I0941c93b76fb0aa8eedb883a3ed1167c6e14d0c0

includes/filerepo/LocalRepo.php
includes/specials/SpecialMovepage.php

index 549be40..9b62243 100644 (file)
@@ -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 );
+                       $wgMemc->add( $memcKey, " ", $expiry );
                        return false;
                }
                $dbr = $this->getSlaveDB();
@@ -190,10 +190,10 @@ class LocalRepo extends FileRepo {
 
                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;
                }
        }
@@ -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 );
                }
        }
 }
index 0e342cc..1dc4244 100644 (file)
@@ -692,13 +692,6 @@ class MovePageForm extends UnlistedSpecialPage {
                # Deal with watches (we don't watch subpages)
                WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
                WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
-
-               # Re-clear the file redirect cache, which may have been polluted by
-               # parsing in messages above. See CR r56745.
-               # @todo FIXME: Needs a more robust solution inside FileRepo.
-               if ( $ot->getNamespace() == NS_FILE ) {
-                       RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
-               }
        }
 
        function showLogFragment( $title ) {