Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310804

Change subject: Remove global state from DatabaseBase::__construct()
......................................................................

Remove global state from DatabaseBase::__construct()

Change-Id: Iba347fce8f0f531aa7e565bb8806260bcbf04a98
---
M includes/db/Database.php
M includes/db/loadbalancer/LBFactorySimple.php
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
3 files changed, 17 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/310804/1

diff --git a/includes/db/Database.php b/includes/db/Database.php
index 0c357cc..917bc91 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -239,18 +239,14 @@
         * @param array $params Parameters passed from DatabaseBase::factory()
         */
        function __construct( array $params ) {
-               global $wgDBprefix, $wgDBmwschema;
-
-               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
-
                $server = $params['host'];
                $user = $params['user'];
                $password = $params['password'];
                $dbName = $params['dbname'];
                $flags = $params['flags'];
-               $tablePrefix = $params['tablePrefix'];
-               $schema = $params['schema'];
-               $foreign = $params['foreign'];
+
+               $this->mSchema = $params['schema'];
+               $this->mTablePrefix = $params['tablePrefix'];
 
                $this->cliMode = isset( $params['cliMode'] )
                        ? $params['cliMode']
@@ -267,21 +263,11 @@
 
                $this->mSessionVars = $params['variables'];
 
-               /** Get the default table prefix*/
-               if ( $tablePrefix === 'get from global' ) {
-                       $this->mTablePrefix = $wgDBprefix;
-               } else {
-                       $this->mTablePrefix = $tablePrefix;
-               }
+               $this->mForeign = $params['foreign'];
 
-               /** Get the database schema*/
-               if ( $schema === 'get from global' ) {
-                       $this->mSchema = $wgDBmwschema;
-               } else {
-                       $this->mSchema = $schema;
-               }
-
-               $this->mForeign = $foreign;
+               $this->srvCache = isset( $params['srvCache'] )
+                       ? $params['srvCache']
+                       : new EmptyBagOStuff();
 
                $this->profiler = isset( $params['profiler'] )
                        ? $params['profiler']
@@ -378,7 +364,7 @@
                        $p['dbname'] = isset( $p['dbname'] ) ? $p['dbname'] : 
false;
                        $p['flags'] = isset( $p['flags'] ) ? $p['flags'] : 0;
                        $p['variables'] = isset( $p['variables'] ) ? 
$p['variables'] : [];
-                       $p['tablePrefix'] = isset( $p['tablePrefix'] ) ? 
$p['tablePrefix'] : 'get from global';
+                       $p['tablePrefix'] = isset( $p['tablePrefix'] ) ? 
$p['tablePrefix'] : '';
                        if ( !isset( $p['schema'] ) ) {
                                $p['schema'] = isset( $defaultSchemas[$dbType] 
) ? $defaultSchemas[$dbType] : null;
                        }
diff --git a/includes/db/loadbalancer/LBFactorySimple.php 
b/includes/db/loadbalancer/LBFactorySimple.php
index 908453c..9e9c2f1 100644
--- a/includes/db/loadbalancer/LBFactorySimple.php
+++ b/includes/db/loadbalancer/LBFactorySimple.php
@@ -46,7 +46,7 @@
         * @return LoadBalancer
         */
        public function newMainLB( $wiki = false ) {
-               global $wgDBservers;
+               global $wgDBservers, $wgDBprefix, $wgDBmwschema;
 
                if ( is_array( $wgDBservers ) ) {
                        $servers = $wgDBservers;
@@ -56,7 +56,11 @@
                                } else {
                                        $server['replica'] = true;
                                }
-                               $server += [ 'flags' => DBO_DEFAULT ];
+                               $server += [
+                                       'schema' => $wgDBmwschema,
+                                       'tablePrefix' => $wgDBprefix,
+                                       'flags' => DBO_DEFAULT
+                               ];
                        }
                } else {
                        global $wgDBserver, $wgDBuser, $wgDBpassword, 
$wgDBname, $wgDBtype, $wgDebugDumpSql;
@@ -78,6 +82,8 @@
                                'user' => $wgDBuser,
                                'password' => $wgDBpassword,
                                'dbname' => $wgDBname,
+                               'schema' => $wgDBmwschema,
+                               'tablePrefix' => $wgDBprefix,
                                'type' => $wgDBtype,
                                'load' => 1,
                                'flags' => $flags,
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index 903c160..824279d 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -803,6 +803,7 @@
                                "{$this->connsOpened}+ connections made 
(master=$masterName)" );
                }
 
+               $server['srvCache'] = $this->srvCache;
                // Set loggers
                $server['connLogger'] = $this->connLogger;
                $server['queryLogger'] = $this->queryLogger;

-- 
To view, visit https://gerrit.wikimedia.org/r/310804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba347fce8f0f531aa7e565bb8806260bcbf04a98
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to