MediaWiki REL1_39
benchmarkCommentFormatter.php
Go to the documentation of this file.
1<?php
2
5
6require_once __DIR__ . '/../includes/Benchmarker.php';
7
9 public function __construct() {
10 parent::__construct();
11 $this->addDescription( 'Benchmark Linker::formatComment()' );
12 $this->addOption( 'file', 'A JSON API result from list=recentchanges',
13 false, true );
14 }
15
16 public function execute() {
17 $file = $this->getOption( 'file',
18 __DIR__ . '/data/CommentFormatter/rc100-2021-07-29.json' );
19 $json = file_get_contents( $file );
20 if ( !$json ) {
21 $this->fatalError( "Unable to read input file \"$file\"" );
22 }
23 $result = json_decode( $json, true );
24 if ( !isset( $result['query']['recentchanges'] ) ) {
25 $this->fatalError( "Invalid JSON data" );
26 }
27 $entries = $result['query']['recentchanges'];
28 $inputs = [];
29 $comments = [];
30 foreach ( $entries as $entry ) {
31 $inputs[] = [
32 'comment' => $entry['comment'],
33 'title' => Title::newFromText( $entry['title'] )
34 ];
35 $comments[] = $entry['comment'];
36 }
37 $this->bench( [
38 'Linker::formatComment' => [
39 'function' => static function () use ( $inputs ) {
40 Title::clearCaches();
41 foreach ( $inputs as $input ) {
43 $input['comment'],
44 $input['title']
45 );
46 }
47 },
48 ],
49
50 'CommentFormatter::createBatch' => [
51 'function' => static function () use ( $inputs ) {
52 Title::clearCaches();
53 $formatter = MediaWikiServices::getInstance()->getCommentFormatter();
54 $comments = [];
55 foreach ( $inputs as $input ) {
56 $comments[] = ( new CommentItem( $input['comment'] ) )
57 ->selfLinkTarget( $input['title'] );
58 }
59 $formatter->createBatch()
60 ->comments( $comments )
61 ->execute();
62 }
63 ],
64
65 'CommentFormatter::formatStrings' => [
66 'function' => static function () use ( $comments ) {
67 Title::clearCaches();
68 $formatter = MediaWikiServices::getInstance()->getCommentFormatter();
69 $formatter->formatStrings( $comments );
70 }
71 ],
72
73 ] );
74 }
75}
76
77$maintClass = BenchmarkCommentFormatter::class;
78require_once RUN_MAINTENANCE_IF_MAIN;
Base class for benchmark scripts.
bench(array $benchs)
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition Linker.php:1449
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
An object to represent one of the inputs to a batch formatting operation.
Service locator for MediaWiki core services.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42