Merge "Add support for Argon2 password hashing"
[lhc/web/wiklou.git] / includes / parser / ParserCache.php
index 5e6081d..ce7ae13 100644 (file)
@@ -145,6 +145,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.
@@ -181,7 +194,7 @@ class ParserCache {
                        $this->getOptionsKey( $article ), $casToken, 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,7 +251,7 @@ class ParserCache {
                        $useOutdated ? self::USE_OUTDATED : self::USE_CURRENT_ONLY
                );
                if ( $parserOutputKey === false ) {
-                       wfIncrStats( 'pcache.miss.absent' );
+                       $this->incrementStats( $article, 'miss.absent' );
                        return false;
                }
 
@@ -247,7 +260,7 @@ class ParserCache {
                $value = $this->mMemc->get( $parserOutputKey, $casToken, 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;
@@ -301,6 +314,10 @@ class ParserCache {
                $cacheTime = null,
                $revId = null
        ) {
+               if ( !$parserOutput->hasText() ) {
+                       throw new InvalidArgumentException( 'Attempt to cache a ParserOutput with no text set!' );
+               }
+
                $expire = $parserOutput->getCacheExpiry();
                if ( $expire > 0 && !$this->mMemc instanceof EmptyBagOStuff ) {
                        $cacheTime = $cacheTime ?: wfTimestampNow();