From b1b01d8e3c490da04c4d0f2aac6e11414e21b6b6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 3 Aug 2019 23:38:54 -0400 Subject: [PATCH] Make NameTableStore use LoadBalancer::getConnectionRef() This method handles reuseConnection() calls, disallows writes to DB_REPLICA role handles, is more consistent with wfGetDB(), and is more efficient with I540b08920997c5. Change-Id: I8edaef0ea4718414e2004fad04afca8ec5797669 --- includes/Storage/NameTableStore.php | 2 +- tests/phpunit/includes/Storage/NameTableStoreTest.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/Storage/NameTableStore.php b/includes/Storage/NameTableStore.php index 5ef03042dc..f8a1f5cccf 100644 --- a/includes/Storage/NameTableStore.php +++ b/includes/Storage/NameTableStore.php @@ -111,7 +111,7 @@ class NameTableStore { * @return IDatabase */ private function getDBConnection( $index, $flags = 0 ) { - return $this->loadBalancer->getConnection( $index, [], $this->domain, $flags ); + return $this->loadBalancer->getConnectionRef( $index, [], $this->domain, $flags ); } /** diff --git a/tests/phpunit/includes/Storage/NameTableStoreTest.php b/tests/phpunit/includes/Storage/NameTableStoreTest.php index 47d3b92747..7a4ea2dd61 100644 --- a/tests/phpunit/includes/Storage/NameTableStoreTest.php +++ b/tests/phpunit/includes/Storage/NameTableStoreTest.php @@ -12,6 +12,7 @@ use Psr\Log\NullLogger; use WANObjectCache; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\LoadBalancer; +use Wikimedia\Rdbms\MaintainableDBConnRef; use Wikimedia\TestingAccessWrapper; /** @@ -51,8 +52,10 @@ class NameTableStoreTest extends MediaWikiTestCase { ->disableOriginalConstructor() ->getMock(); $mock->expects( $this->any() ) - ->method( 'getConnection' ) - ->willReturn( $db ); + ->method( 'getConnectionRef' ) + ->willReturnCallback( function ( $i ) use ( $mock, $db ) { + return new MaintainableDBConnRef( $mock, $db, $i ); + } ); return $mock; } -- 2.20.1