ClassicInterwikiLookup: inject load balancer
Per todo comments, to avoid using wfGetDB Change-Id: Ic4a7f9c5bcbfef3042e5ec0606babbd14d3e6124
This commit is contained in:
parent
3b0fc51124
commit
ebf762cc67
3 changed files with 14 additions and 2 deletions
|
|
@ -562,6 +562,7 @@ return [
|
|||
$services->getContentLanguage(),
|
||||
$services->getMainWANObjectCache(),
|
||||
$services->getHookContainer(),
|
||||
$services->getDBLoadBalancer(),
|
||||
$config->get( 'InterwikiExpiry' ),
|
||||
$config->get( 'InterwikiCache' ),
|
||||
$config->get( 'InterwikiScopes' ),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ use MediaWiki\HookContainer\HookRunner;
|
|||
use WANObjectCache;
|
||||
use WikiMap;
|
||||
use Wikimedia\Rdbms\Database;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
* InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26).
|
||||
|
|
@ -95,10 +96,14 @@ class ClassicInterwikiLookup implements InterwikiLookup {
|
|||
/** @var HookRunner */
|
||||
private $hookRunner;
|
||||
|
||||
/** @var ILoadBalancer */
|
||||
private $loadBalancer;
|
||||
|
||||
/**
|
||||
* @param Language $contLang Language object used to convert prefixes to lower case
|
||||
* @param WANObjectCache $objectCache Cache for interwiki info retrieved from the database
|
||||
* @param HookContainer $hookContainer
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param int $objectCacheExpiry Expiry time for $objectCache, in seconds
|
||||
* @param bool|array|string $cdbData The path of a CDB file, or
|
||||
* an array resembling the contents of a CDB file,
|
||||
|
|
@ -113,6 +118,7 @@ class ClassicInterwikiLookup implements InterwikiLookup {
|
|||
Language $contLang,
|
||||
WANObjectCache $objectCache,
|
||||
HookContainer $hookContainer,
|
||||
ILoadBalancer $loadBalancer,
|
||||
$objectCacheExpiry,
|
||||
$cdbData,
|
||||
$interwikiScopes,
|
||||
|
|
@ -123,6 +129,7 @@ class ClassicInterwikiLookup implements InterwikiLookup {
|
|||
$this->contLang = $contLang;
|
||||
$this->objectCache = $objectCache;
|
||||
$this->hookRunner = new HookRunner( $hookContainer );
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->objectCacheExpiry = $objectCacheExpiry;
|
||||
$this->cdbData = $cdbData;
|
||||
$this->interwikiScopes = $interwikiScopes;
|
||||
|
|
@ -295,7 +302,7 @@ class ClassicInterwikiLookup implements InterwikiLookup {
|
|||
$this->objectCache->makeKey( 'interwiki', $prefix ),
|
||||
$this->objectCacheExpiry,
|
||||
function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix, $fname ) {
|
||||
$dbr = wfGetDB( DB_REPLICA ); // TODO: inject LoadBalancer
|
||||
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
||||
|
||||
$setOpts += Database::getCacheSetOptions( $dbr );
|
||||
|
||||
|
|
@ -445,7 +452,7 @@ class ClassicInterwikiLookup implements InterwikiLookup {
|
|||
* @return array[] Interwiki rows
|
||||
*/
|
||||
private function getAllPrefixesDB( $local ) {
|
||||
$db = wfGetDB( DB_REPLICA ); // TODO: inject DB LoadBalancer
|
||||
$db = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
||||
|
||||
$where = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class ClassicInterwikiLookupTest extends MediaWikiIntegrationTestCase {
|
|||
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
|
||||
WANObjectCache::newEmpty(),
|
||||
MediaWikiServices::getInstance()->getHookContainer(),
|
||||
MediaWikiServices::getInstance()->getDBLoadBalancer(),
|
||||
60 * 60,
|
||||
false,
|
||||
3,
|
||||
|
|
@ -156,6 +157,7 @@ class ClassicInterwikiLookupTest extends MediaWikiIntegrationTestCase {
|
|||
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
|
||||
WANObjectCache::newEmpty(),
|
||||
MediaWikiServices::getInstance()->getHookContainer(),
|
||||
MediaWikiServices::getInstance()->getDBLoadBalancer(),
|
||||
60 * 60,
|
||||
$cdbFile,
|
||||
3,
|
||||
|
|
@ -208,6 +210,7 @@ class ClassicInterwikiLookupTest extends MediaWikiIntegrationTestCase {
|
|||
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
|
||||
WANObjectCache::newEmpty(),
|
||||
MediaWikiServices::getInstance()->getHookContainer(),
|
||||
MediaWikiServices::getInstance()->getDBLoadBalancer(),
|
||||
60 * 60,
|
||||
$hash,
|
||||
3,
|
||||
|
|
@ -262,6 +265,7 @@ class ClassicInterwikiLookupTest extends MediaWikiIntegrationTestCase {
|
|||
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
|
||||
WANObjectCache::newEmpty(),
|
||||
MediaWikiServices::getInstance()->getHookContainer(),
|
||||
MediaWikiServices::getInstance()->getDBLoadBalancer(),
|
||||
60 * 60,
|
||||
$hash,
|
||||
3,
|
||||
|
|
|
|||
Loading…
Reference in a new issue