Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / parser / ParserCache.php
index 43c72b1..2585872 100644 (file)
@@ -57,6 +57,7 @@ class ParserCache {
         * @var string
         */
        private $cacheEpoch;
+
        /**
         * Get an instance of this object
         *
@@ -145,6 +146,19 @@ class ParserCache {
                return is_object( $value ) ? $value : false;
        }
 
+       /**
+        * @param WikiPage $article
+        * @param string $metricSuffix
+        */
+       private function incrementStats( $article, $metricSuffix ) {
+               // old style global metric (can be removed once no longer used)
+               wfIncrStats( 'pcache.' . $metricSuffix );
+               // new per content model metric
+               $contentModel = str_replace( '.', '_', $article->getContentModel() );
+               $metricSuffix = str_replace( '.', '_', $metricSuffix );
+               wfIncrStats( 'pcache.' . $contentModel . '.' . $metricSuffix );
+       }
+
        /**
         * Generates a key for caching the given article considering
         * the given parser options.
@@ -176,12 +190,11 @@ class ParserCache {
                }
 
                // Determine the options which affect this article
-               $casToken = null;
                $optionsKey = $this->mMemc->get(
-                       $this->getOptionsKey( $article ), $casToken, BagOStuff::READ_VERIFIED );
+                       $this->getOptionsKey( $article ), BagOStuff::READ_VERIFIED );
                if ( $optionsKey instanceof CacheTime ) {
                        if ( $useOutdated < self::USE_EXPIRED && $optionsKey->expired( $article->getTouched() ) ) {
-                               wfIncrStats( "pcache.miss.expired" );
+                               $this->incrementStats( $article, "miss.expired" );
                                $cacheTime = $optionsKey->getCacheTime();
                                wfDebugLog( "ParserCache",
                                        "Parser options key expired, touched " . $article->getTouched()
@@ -190,7 +203,7 @@ class ParserCache {
                        } elseif ( $useOutdated < self::USE_OUTDATED &&
                                $optionsKey->isDifferentRevision( $article->getLatest() )
                        ) {
-                               wfIncrStats( "pcache.miss.revid" );
+                               $this->incrementStats( $article, "miss.revid" );
                                $revId = $article->getLatest();
                                $cachedRevId = $optionsKey->getCacheRevisionId();
                                wfDebugLog( "ParserCache",
@@ -238,16 +251,16 @@ class ParserCache {
                        $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
                );
                if ( $parserOutputKey === false ) {
-                       wfIncrStats( 'pcache.miss.absent' );
+                       $this->incrementStats( $article, 'miss.absent' );
                        return false;
                }
 
                $casToken = null;
                /** @var ParserOutput $value */
-               $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED );
+               $value = $this->mMemc->get( $parserOutputKey, BagOStuff::READ_VERIFIED );
                if ( !$value ) {
                        wfDebug( "ParserOutput cache miss.\n" );
-                       wfIncrStats( "pcache.miss.absent" );
+                       $this->incrementStats( $article, "miss.absent" );
                        return false;
                }
 
@@ -258,14 +271,14 @@ class ParserCache {
                        : $article;
 
                if ( !$useOutdated && $value->expired( $touched ) ) {
-                       wfIncrStats( "pcache.miss.expired" );
+                       $this->incrementStats( $article, "miss.expired" );
                        $cacheTime = $value->getCacheTime();
                        wfDebugLog( "ParserCache",
                                "ParserOutput key expired, touched $touched, "
                                . "epoch {$this->cacheEpoch}, cached $cacheTime\n" );
                        $value = false;
                } elseif ( !$useOutdated && $value->isDifferentRevision( $article->getLatest() ) ) {
-                       wfIncrStats( "pcache.miss.revid" );
+                       $this->incrementStats( $article, "miss.revid" );
                        $revId = $article->getLatest();
                        $cachedRevId = $value->getCacheRevisionId();
                        wfDebugLog( "ParserCache",
@@ -275,13 +288,13 @@ class ParserCache {
                } elseif (
                        Hooks::run( 'RejectParserCacheValue', [ $value, $wikiPage, $popts ] ) === false
                ) {
-                       wfIncrStats( 'pcache.miss.rejected' );
+                       $this->incrementStats( $article, 'miss.rejected' );
                        wfDebugLog( "ParserCache",
                                "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"
                        );
                        $value = false;
                } else {
-                       wfIncrStats( "pcache.hit" );
+                       $this->incrementStats( $article, "hit" );
                }
 
                return $value;