'BenchmarkDeleteTruncate' => __DIR__ . '/maintenance/benchmarks/bench_delete_truncate.php',
'BenchmarkHooks' => __DIR__ . '/maintenance/benchmarks/benchmarkHooks.php',
'BenchmarkJSMinPlus' => __DIR__ . '/maintenance/benchmarks/benchmarkJSMinPlus.php',
+ 'BenchmarkJavaScriptMinifier' => __DIR__ . '/maintenance/benchmarks/benchmarkJavaScriptMinifier.php',
'BenchmarkLruHash' => __DIR__ . '/maintenance/benchmarks/benchmarkLruHash.php',
'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php',
'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php',
*/
use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\MaintainableDBConnRef;
+use Wikimedia\Rdbms\DatabaseDomain;
/**
* DB accessible external objects.
* Get a LoadBalancer for the specified cluster
*
* @param string $cluster Cluster name
- * @return LoadBalancer
+ * @return ILoadBalancer
*/
private function getLoadBalancer( $cluster ) {
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
public function getSlave( $cluster ) {
global $wgDefaultExternalStore;
- $wiki = $this->params['wiki'] ?? false;
$lb = $this->getLoadBalancer( $cluster );
+ $domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
if ( !in_array( "DB://" . $cluster, (array)$wgDefaultExternalStore ) ) {
wfDebug( "read only external store\n" );
wfDebug( "writable external store\n" );
}
- $db = $lb->getConnectionRef( DB_REPLICA, [], $wiki );
+ $db = $lb->getConnectionRef( DB_REPLICA, [], $domainId );
$db->clearFlag( DBO_TRX ); // sanity
return $db;
* @return MaintainableDBConnRef
*/
public function getMaster( $cluster ) {
- $wiki = $this->params['wiki'] ?? false;
$lb = $this->getLoadBalancer( $cluster );
+ $domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
- $db = $lb->getMaintenanceConnectionRef( DB_MASTER, [], $wiki );
+ $db = $lb->getMaintenanceConnectionRef( DB_MASTER, [], $domainId );
$db->clearFlag( DBO_TRX ); // sanity
return $db;
}
+ /**
+ * @param array $server Master DB server configuration array for LoadBalancer
+ * @return string|bool Database domain ID or false
+ */
+ private function getDomainId( array $server ) {
+ if ( isset( $server['dbname'] ) ) {
+ // T200471: for b/c, treat any "dbname" field as forcing which database to use.
+ // MediaWiki/LoadBalancer previously did not enforce any concept of a local DB
+ // domain, but rather assumed that the LB server configuration matched $wgDBname.
+ // This check is useful when the external storage DB for this cluster does not use
+ // the same name as the corresponding "main" DB(s) for wikis.
+ $domain = new DatabaseDomain(
+ $server['dbname'],
+ $server['schema'] ?? null,
+ $server['tablePrefix'] ?? ''
+ );
+
+ return $domain->getId();
+ }
+
+ return $this->params['wiki'] ?? false; // local domain unless explictly given
+ }
+
/**
* Get the 'blobs' table name for this database
*
* Return the server info structure for a given index, or false if the index is invalid.
* @param int $i
* @return array|bool
+ * @since 1.31
*/
public function getServerInfo( $i );
$this->lang->formatSize( memory_get_peak_usage( true ) )
) );
}
+
+ /**
+ * @since 1.32
+ * @param string $file Path to file (maybe compressed with gzip)
+ * @return string Contents of file
+ */
+ protected function loadFile( $file ) {
+ $content = file_get_contents( $file );
+ // Detect GZIP compression header
+ if ( substr( $content, 0, 2 ) === "\037\213" ) {
+ $content = gzdecode( $content );
+ }
+ return $content;
+ }
}
],
] );
}
-
- private function loadFile( $file ) {
- $css = file_get_contents( $file );
- // Detect GZIP compression header
- if ( substr( $css, 0, 2 ) === "\037\213" ) {
- $css = gzdecode( $css );
- }
- return $css;
- }
}
$maintClass = BenchmarkCSSMin::class;
--- /dev/null
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Benchmark
+ * @author Timo Tijhof
+ */
+
+require_once __DIR__ . '/Benchmarker.php';
+
+/**
+ * Maintenance script that benchmarks JavaScriptMinifier.
+ *
+ * @ingroup Benchmark
+ */
+class BenchmarkJavaScriptMinifier extends Benchmarker {
+ protected $defaultCount = 10;
+
+ public function __construct() {
+ parent::__construct();
+ $this->addDescription( 'Benchmark for JavaScriptMinifier.' );
+ $this->addOption( 'file', 'Path to JavaScript file (may be gzipped)', false, true );
+ }
+
+ public function execute() {
+ $file = $this->getOption( 'file', __DIR__ . '/jsmin/jquery-3.2.1.js.gz' );
+ $filename = basename( $file );
+ $content = $this->loadFile( $file );
+ if ( $content === false ) {
+ $this->fatalError( 'Unable to open input file' );
+ }
+
+ $this->bench( [
+ "minify ($filename)" => [
+ 'function' => [ JavaScriptMinifier::class, 'minify' ],
+ 'args' => [ $content ],
+ ],
+ ] );
+ }
+}
+
+$maintClass = BenchmarkJavaScriptMinifier::class;
+require_once RUN_MAINTENANCE_IF_MAIN;
use MediaWiki\MediaWikiServices;
-require __DIR__ . '/../Maintenance.php';
+require __DIR__ . '/Benchmarker.php';
-class BenchmarkTidy extends Maintenance {
+class BenchmarkTidy extends Benchmarker {
public function __construct() {
parent::__construct();
- $this->addOption( 'file', 'A filename which contains the input text', true, true );
+ $this->addOption( 'file', 'Path to file containing the input text', false, true );
$this->addOption( 'driver', 'The Tidy driver name, or false to use the configured instance',
false, true );
$this->addOption( 'tidy-config', 'JSON encoded value for the tidy configuration array',
}
public function execute() {
- $html = file_get_contents( $this->getOption( 'file' ) );
+ $file = $this->getOption( 'file', __DIR__ . '/tidy/australia-untidy.html.gz' );
+ $html = $this->loadFile( $file );
if ( $html === false ) {
$this->fatalError( "Unable to open input file" );
}