X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fbenchmarks%2FbenchmarkParse.php;h=a613f96cc89b27a6a27254e85507ea15ad05170d;hb=d8d2b2873f7cc7a81290f462e6584ae68c937c7a;hp=b850e638d040e03fab688e7c5718c342523eda43;hpb=174f34a86de3162bc673fd3bc6bed815cccf0edc;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/benchmarks/benchmarkParse.php b/maintenance/benchmarks/benchmarkParse.php index b850e638d0..a613f96cc8 100644 --- a/maintenance/benchmarks/benchmarkParse.php +++ b/maintenance/benchmarks/benchmarkParse.php @@ -24,6 +24,8 @@ 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 @@ -34,8 +36,15 @@ class BenchmarkParse extends Maintenance { /** @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(); @@ -52,14 +61,20 @@ class BenchmarkParse extends Maintenance { '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" ); @@ -91,7 +106,7 @@ class BenchmarkParse extends Maintenance { $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 ); @@ -118,19 +133,19 @@ class BenchmarkParse extends Maintenance { * @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; @@ -144,6 +159,9 @@ class BenchmarkParse extends Maintenance { function runParser( Revision $revision ) { $content = $revision->getContent(); $content->getParserOutput( $revision->getTitle(), $revision->getId() ); + if ( $this->clearLinkCache ) { + $this->linkCache->clear(); + } } /**