require __DIR__ . '/../Maintenance.php';
+use MediaWiki\MediaWikiServices;
+
/**
* Maintenance script to benchmark how long it takes to parse a given title at an optionally
* specified timestamp
/** @var string MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS) */
private $templateTimestamp = null;
+ private $clearLinkCache = false;
+
+ /**
+ * @var LinkCache
+ */
+ private $linkCache;
+
/** @var array Cache that maps a Title DB key to revision ID for the requested timestamp */
private $idCache = [];
'Use templates which were current at the given time (except that moves and ' .
'deletes are not handled properly)',
false, true );
+ $this->addOption( 'reset-linkcache', 'Reset the LinkCache after every parse.',
+ false, false );
}
function execute() {
Hooks::register( 'BeforeParserFetchTemplateAndtitle', [ $this, 'onFetchTemplate' ] );
}
+ $this->clearLinkCache = $this->hasOption( 'reset-linkcache' );
+ // Set as a member variable to avoid function calls when we're timing the parse
+ $this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
+
$title = Title::newFromText( $this->getArg() );
if ( !$title ) {
$this->error( "Invalid title" );
function runParser( Revision $revision ) {
$content = $revision->getContent();
$content->getParserOutput( $revision->getTitle(), $revision->getId() );
+ if ( $this->clearLinkCache ) {
+ $this->linkCache->clear();
+ }
}
/**