storage: rename various $wikiId fields/parameters to $dbDomain
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 27 Jun 2019 01:32:34 +0000 (18:32 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 28 Jun 2019 00:57:04 +0000 (00:57 +0000)
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
includes/Storage/NameTableStore.php
includes/Storage/SqlBlobStore.php
tests/phpunit/includes/Storage/BlobStoreFactoryTest.php

index 368ca48..8262446 100644 (file)
@@ -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' ) );
index a14e339..5ef0304 100644 (file)
@@ -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
index e0e14b0..7fe5643 100644 (file)
@@ -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 {
index 252c657..0249730 100644 (file)
@@ -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 );
        }
 
 }