From 2d20924ebfc9572f58823cc260223e2d4753fec2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 15 Jul 2019 20:33:38 -0700 Subject: [PATCH] Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer() Note that only one extension uses this class and should not be affected. Also, make the constructor take an optional LoadBalancer for DI. Change-Id: Ibb7192ac199427266d7e3f3f14437d0495061911 --- includes/dao/DBAccessBase.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/includes/dao/DBAccessBase.php b/includes/dao/DBAccessBase.php index e099b38f09..09314ed3ca 100644 --- a/includes/dao/DBAccessBase.php +++ b/includes/dao/DBAccessBase.php @@ -32,24 +32,24 @@ use Wikimedia\Rdbms\ILoadBalancer; * @author Daniel Kinzler */ abstract class DBAccessBase implements IDBAccessObject { - /** - * @var string|bool $wiki The target wiki's name. This must be an ID - * that LBFactory can understand. - */ - protected $wiki = false; + /** @var ILoadBalancer */ + private $lb; + + /** @var string|bool The target wiki's DB domain */ + protected $dbDomain = false; /** - * @param string|bool $wiki The target wiki's name. This must be an ID - * that LBFactory can understand. + * @param string|bool $dbDomain The target wiki's DB domain */ - public function __construct( $wiki = false ) { - $this->wiki = $wiki; + public function __construct( $dbDomain = false ) { + $this->dbDomain = $dbDomain; + $this->lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory() + ->getMainLB( $dbDomain ); } /** * Returns a database connection. * - * @see wfGetDB() * @see LoadBalancer::getConnection() * * @since 1.21 @@ -60,9 +60,7 @@ abstract class DBAccessBase implements IDBAccessObject { * @return IDatabase */ protected function getConnection( $id, array $groups = [] ) { - $loadBalancer = $this->getLoadBalancer(); - - return $loadBalancer->getConnection( $id, $groups, $this->wiki ); + return $this->getLoadBalancer()->getConnectionRef( $id, $groups, $this->dbDomain ); } /** @@ -73,12 +71,10 @@ abstract class DBAccessBase implements IDBAccessObject { * @since 1.21 * * @param IDatabase $db The database connection to release. + * @deprecated Since 1.34 */ protected function releaseConnection( IDatabase $db ) { - if ( $this->wiki !== false ) { - $loadBalancer = $this->getLoadBalancer(); - $loadBalancer->reuseConnection( $db ); - } + // no-op } /** @@ -90,8 +86,7 @@ abstract class DBAccessBase implements IDBAccessObject { * * @return ILoadBalancer The database load balancer object */ - public function getLoadBalancer() { - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); - return $lbFactory->getMainLB( $this->wiki ); + protected function getLoadBalancer() { + return $this->lb; } } -- 2.20.1