Move variable definitions near to where they are used
authorAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sat, 15 Mar 2014 13:34:52 +0000 (14:34 +0100)
committerAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sat, 15 Mar 2014 13:34:52 +0000 (14:34 +0100)
In LoadBalancer::reuseConnection(), if the condition
"$serverIndex === null || $refCount === null" is met,
then those variables will not be used. So only define
them when they will readlly be used.

Change-Id: Ifbd4131f40d3babe733b8723d0d29d39890bb309

includes/db/LoadBalancer.php

index 5f880d6..de4c2f5 100644 (file)
@@ -493,13 +493,6 @@ class LoadBalancer {
        public function reuseConnection( $conn ) {
                $serverIndex = $conn->getLBInfo( 'serverIndex' );
                $refCount = $conn->getLBInfo( 'foreignPoolRefCount' );
-               $dbName = $conn->getDBname();
-               $prefix = $conn->tablePrefix();
-               if ( strval( $prefix ) !== '' ) {
-                       $wiki = "$dbName-$prefix";
-               } else {
-                       $wiki = $dbName;
-               }
                if ( $serverIndex === null || $refCount === null ) {
                        wfDebug( __METHOD__ . ": this connection was not opened as a foreign connection\n" );
 
@@ -516,6 +509,14 @@ class LoadBalancer {
 
                        return;
                }
+
+               $dbName = $conn->getDBname();
+               $prefix = $conn->tablePrefix();
+               if ( strval( $prefix ) !== '' ) {
+                       $wiki = "$dbName-$prefix";
+               } else {
+                       $wiki = $dbName;
+               }
                if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) {
                        throw new MWException( __METHOD__ . ": connection not found, has " .
                                "the connection been freed already?" );