From 58afeaf93c0977f7739eb4be3c4ad08d58637fff Mon Sep 17 00:00:00 2001 From: Fomafix Date: Wed, 4 Sep 2024 13:27:15 +0000 Subject: [PATCH] Use IConnectionProvider instead of ILoadBalancer Change-Id: Id1071e0a61030c2ddd01fecebf6bf8a99c5948e0 --- includes/CategoryCache.php | 10 +++++----- includes/ServiceWiring.php | 2 +- tests/phpunit/CategoryCacheTest.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/CategoryCache.php b/includes/CategoryCache.php index 8f225557..5717ada9 100644 --- a/includes/CategoryCache.php +++ b/includes/CategoryCache.php @@ -22,7 +22,7 @@ namespace MediaWiki\Extension\CategoryTree; use MediaWiki\Category\Category; use MediaWiki\Linker\LinkTarget; -use Wikimedia\Rdbms\ILoadBalancer; +use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IResultWrapper; /** @@ -32,12 +32,12 @@ class CategoryCache { /** @var (?Category)[] Keys are category database names, values are either a Category object or null */ private array $cache = []; - private ILoadBalancer $loadBalancer; + private IConnectionProvider $dbProvider; public function __construct( - ILoadBalancer $loadBalancer + IConnectionProvider $dbProvider ) { - $this->loadBalancer = $loadBalancer; + $this->dbProvider = $dbProvider; } /** @@ -78,7 +78,7 @@ class CategoryCache { return; } - $rows = $this->loadBalancer->getConnection( ILoadBalancer::DB_REPLICA ) + $rows = $this->dbProvider->getReplicaDatabase() ->newSelectQueryBuilder() ->select( [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ] ) ->from( 'category' ) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 095bf939..c9b57b95 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -33,7 +33,7 @@ use MediaWiki\MediaWikiServices; return [ 'CategoryTree.CategoryCache' => static function ( MediaWikiServices $services ): CategoryCache { return new CategoryCache( - $services->getDBLoadBalancer() + $services->getConnectionProvider() ); }, ]; diff --git a/tests/phpunit/CategoryCacheTest.php b/tests/phpunit/CategoryCacheTest.php index 9cf9e5b0..abb5624f 100644 --- a/tests/phpunit/CategoryCacheTest.php +++ b/tests/phpunit/CategoryCacheTest.php @@ -24,7 +24,7 @@ use MediaWiki\Category\Category; use MediaWiki\Extension\CategoryTree\CategoryCache; use MediaWiki\Title\TitleValue; use MediaWikiIntegrationTestCase; -use Wikimedia\Rdbms\ILoadBalancer; +use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\TestingAccessWrapper; /** @@ -35,7 +35,7 @@ class CategoryCacheTest extends MediaWikiIntegrationTestCase { public function testConstruct() { new CategoryCache( - $this->createMock( ILoadBalancer::class ) + $this->createMock( IConnectionProvider::class ) ); $this->addToAssertionCount( 1 ); }