From: daniel Date: Thu, 15 Nov 2018 15:41:29 +0000 (+0100) Subject: Add logging for redundant parsing to WikitextContent. X-Git-Tag: 1.34.0-rc.0~3436^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=commitdiff_plain;h=f503995c51c67d6ced51492041ba50e255469cd3;p=lhc%2Fweb%2Fwiklou.git Add logging for redundant parsing to WikitextContent. Bug: T205369 Change-Id: I67bfdc0340e0ddc1ecdaf3323f2171b2e752c680 --- diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index a7021b1e7b..517d807867 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -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 );