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 = array();
+ private $idCache = [];
function __construct() {
parent::__construct();
'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() {
if ( $this->hasOption( 'tpl-time' ) ) {
$this->templateTimestamp = wfTimestamp( TS_MW, strtotime( $this->getOption( 'tpl-time' ) ) );
- Hooks::register( 'BeforeParserFetchTemplateAndtitle', array( $this, 'onFetchTemplate' ) );
+ 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" );
$loops = $this->getOption( 'loops', 1 );
if ( $loops < 1 ) {
- $this->error( 'Invalid number of loops specified', true );
+ $this->fatalError( 'Invalid number of loops specified' );
}
$startUsage = getrusage();
$startTime = microtime( true );
* @return bool|string Revision ID, or false if not found or error
*/
function getRevIdForTime( Title $title, $timestamp ) {
- $dbr = $this->getDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_REPLICA );
$id = $dbr->selectField(
- array( 'revision', 'page' ),
+ [ 'revision', 'page' ],
'rev_id',
- array(
+ [
'page_namespace' => $title->getNamespace(),
'page_title' => $title->getDBkey(),
'rev_timestamp <= ' . $dbr->addQuotes( $timestamp )
- ),
+ ],
__METHOD__,
- array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 1 ),
- array( 'revision' => array( 'INNER JOIN', 'rev_page=page_id' ) )
+ [ 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 1 ],
+ [ 'revision' => [ 'INNER JOIN', 'rev_page=page_id' ] ]
);
return $id;
function runParser( Revision $revision ) {
$content = $revision->getContent();
$content->getParserOutput( $revision->getTitle(), $revision->getId() );
+ if ( $this->clearLinkCache ) {
+ $this->linkCache->clear();
+ }
}
/**