Merge "Switch the sidebar cache to using checkKeys"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 20 Feb 2018 22:09:50 +0000 (22:09 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 20 Feb 2018 22:09:50 +0000 (22:09 +0000)
1  2 
includes/cache/MessageCache.php

@@@ -300,7 -300,7 +300,7 @@@ class MessageCache 
                }
  
                if ( !$success ) {
-                       $cacheKey = $this->clusterCache->makeKey( 'messages', $code ); # Key in memc for messages
+                       $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
                        # Try the global cache. If it is empty, try to acquire a lock. If
                        # the lock can't be acquired, wait for the other thread to finish
                        # and then try the global cache a second time.
                                // load() calls do try to refresh the cache with replica DB data
                                $this->mCache[$code]['LATEST'] = time();
                                // Pre-emptively update the local datacenter cache so things like edit filter and
 -                              // blacklist changes are reflect immediately, as these often use MediaWiki: pages.
 +                              // blacklist changes are reflected immediately; these often use MediaWiki: pages.
                                // The datacenter handling replace() calls should be the same one handling edits
                                // as they require HTTP POST.
                                $this->saveToCaches( $this->mCache[$code], 'all', $code );
  
                                // Relay the purge. Touching this check key expires cache contents
                                // and local cache (APC) validation hash across all datacenters.
-                               $this->wanCache->touchCheckKey( $this->wanCache->makeKey( 'messages', $code ) );
-                               // Also delete cached sidebar... just in case it is affected
-                               // @TODO: shouldn't this be $code === $wgLanguageCode?
-                               if ( $code === 'en' ) {
-                                       // Purge all language sidebars, e.g. on ?action=purge to the sidebar messages
-                                       $codes = array_keys( Language::fetchLanguageNames() );
-                               } else {
-                                       // Purge only the sidebar for this language
-                                       $codes = [ $code ];
-                               }
-                               foreach ( $codes as $code ) {
-                                       $this->wanCache->delete( $this->wanCache->makeKey( 'sidebar', $code ) );
-                               }
+                               $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
  
                                // Purge the message in the message blob store
                                $resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
                $value = $this->wanCache->get(
                        $this->wanCache->makeKey( 'messages', $code, 'hash', 'v1' ),
                        $curTTL,
-                       [ $this->wanCache->makeKey( 'messages', $code ) ]
+                       [ $this->getCheckKey( $code ) ]
                );
  
                if ( $value ) {
                if ( $useDB ) {
                        $uckey = $wgContLang->ucfirst( $lckey );
  
 -                      if ( !isset( $alreadyTried[ $langcode ] ) ) {
 +                      if ( !isset( $alreadyTried[$langcode] ) ) {
                                $message = $this->getMsgFromNamespace(
                                        $this->getMessagePageName( $langcode, $uckey ),
                                        $langcode
                                if ( $message !== false ) {
                                        return $message;
                                }
 -                              $alreadyTried[ $langcode ] = true;
 +                              $alreadyTried[$langcode] = true;
                        }
                } else {
                        $uckey = null;
                        $fallbackChain = Language::getFallbacksFor( $langcode );
  
                        foreach ( $fallbackChain as $code ) {
 -                              if ( isset( $alreadyTried[ $code ] ) ) {
 +                              if ( isset( $alreadyTried[$code] ) ) {
                                        continue;
                                }
  
                                if ( $message !== false ) {
                                        return $message;
                                }
 -                              $alreadyTried[ $code ] = true;
 +                              $alreadyTried[$code] = true;
                        }
                }
  
                if ( isset( $this->mCache[$code][$title] ) ) {
                        $entry = $this->mCache[$code][$title];
                        if ( substr( $entry, 0, 1 ) === ' ' ) {
 -                              // The message exists, so make sure a string is returned.
 +                              // The message exists and is not '!TOO BIG'
                                return (string)substr( $entry, 1 );
                        } elseif ( $entry === '!NONEXISTENT' ) {
                                return false;
 -                      } elseif ( $entry === '!TOO BIG' ) {
 -                              // Fall through and try invididual message cache below
                        }
 +                      // Fall through and try invididual message cache below
                } else {
                        // XXX: This is not cached in process cache, should it?
                        $message = false;
        /**
         * @param string $message
         * @param bool $interface
 -       * @param string $language Language code
 +       * @param Language $language
         * @param Title $title
         * @return string
         */
 -      function transform( $message, $interface = false, $language = null, $title = null ) {
 +      public function transform( $message, $interface = false, $language = null, $title = null ) {
                // Avoid creating parser if nothing to transform
                if ( strpos( $message, '{{' ) === false ) {
                        return $message;
        /**
         * @return Parser
         */
 -      function getParser() {
 +      public function getParser() {
                global $wgParser, $wgParserConf;
  
                if ( !$this->mParser && isset( $wgParser ) ) {
                return $res;
        }
  
 -      function disable() {
 +      public function disable() {
                $this->mDisable = true;
        }
  
 -      function enable() {
 +      public function enable() {
                $this->mDisable = false;
        }
  
        }
  
        /**
-        * Clear all stored messages. Mainly used after a mass rebuild.
+        * Clear all stored messages in global and local cache
+        *
+        * Mainly used after a mass rebuild
         */
        function clear() {
                $langs = Language::fetchLanguageNames( null, 'mw' );
                foreach ( array_keys( $langs ) as $code ) {
-                       # Global and local caches
-                       $this->wanCache->touchCheckKey( $this->wanCache->makeKey( 'messages', $code ) );
+                       $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
                }
  
                $this->mLoadedLanguages = [];
                }
        }
  
+       /**
+        * @param string $code Language code
+        * @return string WAN cache key usable as a "check key" against language page edits
+        */
+       public function getCheckKey( $code ) {
+               return $this->wanCache->makeKey( 'messages', $code );
+       }
        /**
         * @param Content|null $content Content or null if the message page does not exist
         * @return string|bool|null Returns false if $content is null and null on error