From a9a13a1266ccda4613423d874f01009813f032a2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 26 Jun 2019 18:32:34 -0700 Subject: [PATCH] storage: rename various $wikiId fields/parameters to $dbDomain These fields are passed to methods like LoadBalancer::getConnection() and are already expected to be DB domains. Update various comments as well. Fix a few minor IDEA warnings. Change-Id: If480cc4d7d4a3c2d176ab346e6307e80cd2540c5 --- includes/Storage/BlobStoreFactory.php | 14 ++++++------- includes/Storage/NameTableStore.php | 2 +- includes/Storage/SqlBlobStore.php | 20 +++++++++---------- .../includes/Storage/BlobStoreFactoryTest.php | 18 ++++++++--------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/includes/Storage/BlobStoreFactory.php b/includes/Storage/BlobStoreFactory.php index 368ca485fb..82624467ae 100644 --- a/includes/Storage/BlobStoreFactory.php +++ b/includes/Storage/BlobStoreFactory.php @@ -84,27 +84,27 @@ class BlobStoreFactory { /** * @since 1.31 * - * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki. + * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki. * * @return BlobStore */ - public function newBlobStore( $wikiId = false ) { - return $this->newSqlBlobStore( $wikiId ); + public function newBlobStore( $dbDomain = false ) { + return $this->newSqlBlobStore( $dbDomain ); } /** * @internal Please call newBlobStore and use the BlobStore interface. * - * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki. + * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki. * * @return SqlBlobStore */ - public function newSqlBlobStore( $wikiId = false ) { - $lb = $this->lbFactory->getMainLB( $wikiId ); + public function newSqlBlobStore( $dbDomain = false ) { + $lb = $this->lbFactory->getMainLB( $dbDomain ); $store = new SqlBlobStore( $lb, $this->cache, - $wikiId + $dbDomain ); $store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) ); diff --git a/includes/Storage/NameTableStore.php b/includes/Storage/NameTableStore.php index a14e339020..5ef03042dc 100644 --- a/includes/Storage/NameTableStore.php +++ b/includes/Storage/NameTableStore.php @@ -66,7 +66,7 @@ class NameTableStore { /** * @param ILoadBalancer $dbLoadBalancer A load balancer for acquiring database connections * @param WANObjectCache $cache A cache manager for caching data. This can be the local - * wiki's default instance even if $wikiId refers to a different wiki, since + * wiki's default instance even if $dbDomain refers to a different wiki, since * makeGlobalKey() is used to constructed a key that allows cached names from * the same database to be re-used between wikis. For example, enwiki and frwiki will * use the same cache keys for names from the wikidatawiki database, regardless diff --git a/includes/Storage/SqlBlobStore.php b/includes/Storage/SqlBlobStore.php index e0e14b0cd6..7fe56438f8 100644 --- a/includes/Storage/SqlBlobStore.php +++ b/includes/Storage/SqlBlobStore.php @@ -64,7 +64,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { /** * @var bool|string Wiki ID */ - private $wikiId; + private $dbDomain; /** * @var int @@ -94,21 +94,21 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { /** * @param ILoadBalancer $dbLoadBalancer A load balancer for acquiring database connections * @param WANObjectCache $cache A cache manager for caching blobs. This can be the local - * wiki's default instance even if $wikiId refers to a different wiki, since + * wiki's default instance even if $dbDomain refers to a different wiki, since * makeGlobalKey() is used to constructed a key that allows cached blobs from the * same database to be re-used between wikis. For example, enwiki and frwiki will * use the same cache keys for blobs from the wikidatawiki database, regardless of * the cache's default key space. - * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki. + * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki. */ public function __construct( ILoadBalancer $dbLoadBalancer, WANObjectCache $cache, - $wikiId = false + $dbDomain = false ) { $this->dbLoadBalancer = $dbLoadBalancer; $this->cache = $cache; - $this->wikiId = $wikiId; + $this->dbDomain = $dbDomain; } /** @@ -199,7 +199,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { */ private function getDBConnection( $index ) { $lb = $this->getDBLoadBalancer(); - return $lb->getConnection( $index, [], $this->wikiId ); + return $lb->getConnection( $index, [], $this->dbDomain ); } /** @@ -219,7 +219,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { # Write to external storage if required if ( $this->useExternalStore ) { // Store and get the URL - $data = ExternalStore::insertToDefault( $data ); + $data = ExternalStore::insertToDefault( $data, [ 'wiki' => $this->dbDomain ] ); if ( $flags ) { $flags .= ','; } @@ -368,7 +368,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { return $this->cache->makeGlobalKey( 'BlobStore', 'address', - $this->dbLoadBalancer->resolveDomainID( $this->wikiId ), + $this->dbLoadBalancer->resolveDomainID( $this->dbDomain ), $blobAddress ); } @@ -412,14 +412,14 @@ class SqlBlobStore implements IDBAccessObject, BlobStore { $this->getCacheTTL(), function () use ( $url, $flags ) { // Ignore $setOpts; blobs are immutable and negatives are not cached - $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->wikiId ] ); + $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->dbDomain ] ); return $blob === false ? false : $this->decompressData( $blob, $flags ); }, [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => WANObjectCache::TTL_PROC_LONG ] ); } else { - $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->wikiId ] ); + $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->dbDomain ] ); return $blob === false ? false : $this->decompressData( $blob, $flags ); } } else { diff --git a/tests/phpunit/includes/Storage/BlobStoreFactoryTest.php b/tests/phpunit/includes/Storage/BlobStoreFactoryTest.php index 252c657867..0249730f1d 100644 --- a/tests/phpunit/includes/Storage/BlobStoreFactoryTest.php +++ b/tests/phpunit/includes/Storage/BlobStoreFactoryTest.php @@ -13,34 +13,34 @@ use Wikimedia\TestingAccessWrapper; */ class BlobStoreFactoryTest extends MediaWikiTestCase { - public function provideWikiIds() { + public function provideDbDomains() { yield [ false ]; yield [ 'someWiki' ]; } /** - * @dataProvider provideWikiIds + * @dataProvider provideDbDomains */ - public function testNewBlobStore( $wikiId ) { + public function testNewBlobStore( $dbDomain ) { $factory = MediaWikiServices::getInstance()->getBlobStoreFactory(); - $store = $factory->newBlobStore( $wikiId ); + $store = $factory->newBlobStore( $dbDomain ); $this->assertInstanceOf( BlobStore::class, $store ); // This only works as we currently know this is a SqlBlobStore object $wrapper = TestingAccessWrapper::newFromObject( $store ); - $this->assertEquals( $wikiId, $wrapper->wikiId ); + $this->assertEquals( $dbDomain, $wrapper->dbDomain ); } /** - * @dataProvider provideWikiIds + * @dataProvider provideDbDomains */ - public function testNewSqlBlobStore( $wikiId ) { + public function testNewSqlBlobStore( $dbDomain ) { $factory = MediaWikiServices::getInstance()->getBlobStoreFactory(); - $store = $factory->newSqlBlobStore( $wikiId ); + $store = $factory->newSqlBlobStore( $dbDomain ); $this->assertInstanceOf( SqlBlobStore::class, $store ); $wrapper = TestingAccessWrapper::newFromObject( $store ); - $this->assertEquals( $wikiId, $wrapper->wikiId ); + $this->assertEquals( $dbDomain, $wrapper->dbDomain ); } } -- 2.20.1