Track callers of parseRevisionParsoidHtml.

We are seeing a lot of parser cache writes coming from
parseRevisionParsoidHtml. We should find out what is causing them.

Change-Id: I25440e0d759e19cc9769404beb6911c64d37d3e3
This commit is contained in:
daniel 2023-01-11 15:45:20 +01:00 committed by Bartosz Dziewoński
parent cfdeadfdb8
commit b15aecc68c
4 changed files with 16 additions and 9 deletions

View file

@ -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 ) {

View file

@ -107,7 +107,7 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
return new ContentThreadItemSet;
}
return HookUtils::parseRevisionParsoidHtml( $revision );
return HookUtils::parseRevisionParsoidHtml( $revision, __METHOD__ );
}
/**

View file

@ -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.

View file

@ -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() ) {