Merge "Reduce chance for parser cache race conditions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 30 Sep 2013 17:01:13 +0000 (17:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 30 Sep 2013 17:01:13 +0000 (17:01 +0000)
includes/WikiPage.php
includes/parser/ParserCache.php

index 2265aca..048dd68 100644 (file)
@@ -3518,6 +3518,9 @@ class PoolWorkArticleView extends PoolCounterWork {
                        return false;
                }
 
+               // Reduce effects of race conditions for slow parses (bug 46014)
+               $cacheTime = wfTimestampNow();
+
                $time = - microtime( true );
                $this->parserOutput = $content->getParserOutput( $this->page->getTitle(), $this->revid, $this->parserOptions );
                $time += microtime( true );
@@ -3529,7 +3532,8 @@ class PoolWorkArticleView extends PoolCounterWork {
                }
 
                if ( $this->cacheable && $this->parserOutput->isCacheable() ) {
-                       ParserCache::singleton()->save( $this->parserOutput, $this->page, $this->parserOptions );
+                       ParserCache::singleton()->save(
+                               $this->parserOutput, $this->page, $this->parserOptions, $cacheTime );
                }
 
                // Make sure file cache is not used on uncacheable content.
index 7c5eeb4..7053f13 100644 (file)
@@ -223,19 +223,19 @@ class ParserCache {
         * @param $parserOutput ParserOutput
         * @param $article Article
         * @param $popts ParserOptions
+        * @param $cacheTime Time when the cache was generated
         */
-       public function save( $parserOutput, $article, $popts ) {
+       public function save( $parserOutput, $article, $popts, $cacheTime = null ) {
                $expire = $parserOutput->getCacheExpiry();
-
                if ( $expire > 0 ) {
-                       $now = wfTimestampNow();
+                       $cacheTime = $cacheTime ?: wfTimestampNow();
 
                        $optionsKey = new CacheTime;
                        $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
                        $optionsKey->updateCacheExpiry( $expire );
 
-                       $optionsKey->setCacheTime( $now );
-                       $parserOutput->setCacheTime( $now );
+                       $optionsKey->setCacheTime( $cacheTime );
+                       $parserOutput->setCacheTime( $cacheTime );
 
                        $optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() );
 
@@ -245,8 +245,8 @@ class ParserCache {
                        // Save the timestamp so that we don't have to load the revision row on view
                        $parserOutput->setTimestamp( $article->getTimestamp() );
 
-                       $parserOutput->mText .= "\n<!-- Saved in parser cache with key $parserOutputKey and timestamp $now -->\n";
-                       wfDebug( "Saved in parser cache with key $parserOutputKey and timestamp $now\n" );
+                       $parserOutput->mText .= "\n<!-- Saved in parser cache with key $parserOutputKey and timestamp $cacheTime\n -->\n";
+                       wfDebug( "Saved in parser cache with key $parserOutputKey and timestamp $cacheTime\n" );
 
                        // Save the parser output
                        $this->mMemc->set( $parserOutputKey, $parserOutput, $expire );