diff --git a/includes/ApiDiscussionToolsCompare.php b/includes/ApiDiscussionToolsCompare.php index 48d093570..da0610f9e 100644 --- a/includes/ApiDiscussionToolsCompare.php +++ b/includes/ApiDiscussionToolsCompare.php @@ -91,8 +91,8 @@ class ApiDiscussionToolsCompare extends ApiBase { return; } - $fromItemSet = HookUtils::parseRevisionParsoidHtml( $fromRev ); - $toItemSet = HookUtils::parseRevisionParsoidHtml( $toRev ); + $fromItemSet = HookUtils::parseRevisionParsoidHtml( $fromRev, __METHOD__ ); + $toItemSet = HookUtils::parseRevisionParsoidHtml( $toRev, __METHOD__ ); $removedComments = []; foreach ( $fromItemSet->getCommentItems() as $fromComment ) { diff --git a/includes/ApiDiscussionToolsPageInfo.php b/includes/ApiDiscussionToolsPageInfo.php index a0064cc02..ee12296c7 100644 --- a/includes/ApiDiscussionToolsPageInfo.php +++ b/includes/ApiDiscussionToolsPageInfo.php @@ -107,7 +107,7 @@ class ApiDiscussionToolsPageInfo extends ApiBase { return new ContentThreadItemSet; } - return HookUtils::parseRevisionParsoidHtml( $revision ); + return HookUtils::parseRevisionParsoidHtml( $revision, __METHOD__ ); } /** diff --git a/includes/Hooks/DataUpdatesHooks.php b/includes/Hooks/DataUpdatesHooks.php index 3017a7445..210bdbf4b 100644 --- a/includes/Hooks/DataUpdatesHooks.php +++ b/includes/Hooks/DataUpdatesHooks.php @@ -41,9 +41,10 @@ class DataUpdatesHooks implements RevisionDataUpdatesHook { // TODO Deduplicate work between this and the Echo hook (make it use Parsoid too) $rev = $renderedRevision->getRevision(); if ( HookUtils::isAvailableForTitle( $title ) ) { - $updates[] = new MWCallableUpdate( function () use ( $rev ) { + $method = __METHOD__; + $updates[] = new MWCallableUpdate( function () use ( $rev, $method ) { try { - $threadItemSet = HookUtils::parseRevisionParsoidHtml( $rev ); + $threadItemSet = HookUtils::parseRevisionParsoidHtml( $rev, $method ); $this->threadItemStore->insertThreadItems( $rev, $threadItemSet ); } catch ( Throwable $e ) { // Catch errors, so that they don't cause other updates to fail (T315383), but log them. diff --git a/includes/Hooks/HookUtils.php b/includes/Hooks/HookUtils.php index 6de3b95b2..d336e33da 100644 --- a/includes/Hooks/HookUtils.php +++ b/includes/Hooks/HookUtils.php @@ -90,8 +90,10 @@ class HookUtils { * Parse a revision by using the discussion parser on the HTML provided by Parsoid. * * @param RevisionRecord $revRecord - * @param bool $updateParserCache Whether the parser cache should be updated on cache miss. + * @param string|false $updateParserCacheFor Whether the parser cache should be updated on cache miss. * May be set to false for batch operations to avoid flooding the cache. + * Otherwise, it should be set to the name of the calling method (__METHOD__), + * so we can track what is causing parser cache writes. * * @return ContentThreadItemSet * @throws MWException @@ -99,7 +101,7 @@ class HookUtils { */ public static function parseRevisionParsoidHtml( RevisionRecord $revRecord, - $updateParserCache = true + $updateParserCacheFor ): ContentThreadItemSet { $services = MediaWikiServices::getInstance(); $mainConfig = $services->getMainConfig(); @@ -112,14 +114,18 @@ class HookUtils { Assert::postcondition( $pageRecord !== null, 'Revision had no page' ); $parserOptions = ParserOptions::newFromAnon(); - $parserOptions->setRenderReason( __METHOD__ ); + + if ( $updateParserCacheFor ) { + // $updateParserCache contains the name of the calling method + $parserOptions->setRenderReason( $updateParserCacheFor ); + } $status = $parsoidOutputAccess->getParserOutput( $pageRecord, $parserOptions, $revRecord, // Don't flood the parser cache - $updateParserCache ? 0 : ParsoidOutputAccess::OPT_NO_UPDATE_CACHE + $updateParserCacheFor ? 0 : ParsoidOutputAccess::OPT_NO_UPDATE_CACHE ); if ( !$status->isOK() ) {