Add logging for redundant parsing to WikitextContent.
authordaniel <dkinzler@wikimedia.org>
Thu, 15 Nov 2018 15:41:29 +0000 (16:41 +0100)
committerdaniel <dkinzler@wikimedia.org>
Mon, 26 Nov 2018 22:35:41 +0000 (14:35 -0800)
Bug: T205369
Change-Id: I67bfdc0340e0ddc1ecdaf3323f2171b2e752c680

includes/content/WikitextContent.php

index a7021b1..517d807 100644 (file)
@@ -25,6 +25,7 @@
  * @author Daniel Kinzler
  */
 
+use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -41,6 +42,11 @@ class WikitextContent extends TextContent {
         */
        private $hadSignature = false;
 
+       /**
+        * @var array|null Stack trace of the previous parse
+        */
+       private $previousParseStackTrace = null;
+
        public function __construct( $text ) {
                parent::__construct( $text, CONTENT_MODEL_WIKITEXT );
        }
@@ -337,6 +343,28 @@ class WikitextContent extends TextContent {
        ) {
                global $wgParser;
 
+               $stackTrace = ( new RuntimeException() )->getTraceAsString();
+               if ( $this->previousParseStackTrace ) {
+                       // NOTE: there may be legitimate changes to re-parse the same WikiText content,
+                       // e.g. if predicted revision ID for the REVISIONID magic word mismatched.
+                       // But that should be rare.
+                       $logger = LoggerFactory::getInstance( 'DuplicateParse' );
+                       $logger->debug(
+                               __METHOD__ . ': Possibly redundant parse!',
+                               [
+                                       'title' => $title->getPrefixedDBkey(),
+                                       'rev' => $revId,
+                                       'options-hash' => $options->optionsHash(
+                                               ParserOptions::allCacheVaryingOptions(),
+                                               $title
+                                       ),
+                                       'trace' => $stackTrace,
+                                       'previous-trace' => $this->previousParseStackTrace,
+                               ]
+                       );
+               }
+               $this->previousParseStackTrace = $stackTrace;
+
                list( $redir, $text ) = $this->getRedirectTargetAndText();
                $output = $wgParser->parse( $text, $title, $options, true, true, $revId );