Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/244513

Change subject: Use ChangeLookup in dispatchChanges
......................................................................

Use ChangeLookup in dispatchChanges

Also remove usage from DatabaseChangeTransmitterTest

Change-Id: I02189fbfdfc22fa58ca46f5af7c153e24d04b1dc
---
M repo/includes/store/Store.php
M repo/includes/store/sql/SqlStore.php
M repo/maintenance/dispatchChanges.php
M repo/tests/phpunit/includes/Notifications/DatabaseChangeTransmitterTest.php
M repo/tests/phpunit/includes/store/StoreTest.php
5 files changed, 44 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/13/244513/1

diff --git a/repo/includes/store/Store.php b/repo/includes/store/Store.php
index 33f68a3..7455e5f 100644
--- a/repo/includes/store/Store.php
+++ b/repo/includes/store/Store.php
@@ -5,6 +5,7 @@
 use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
 use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\DataModel\Services\Lookup\EntityRedirectLookup;
+use Wikibase\Lib\Store\ChangeLookup;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityStore;
@@ -157,4 +158,11 @@
         */
        public function getEntityPrefetcher();
 
+       /**
+        * @since 0.5
+        *
+        * @return ChangeLookup
+        */
+       public function getChangeLookup();
+
 }
diff --git a/repo/includes/store/sql/SqlStore.php 
b/repo/includes/store/sql/SqlStore.php
index 677f990..231bc4b 100644
--- a/repo/includes/store/sql/SqlStore.php
+++ b/repo/includes/store/sql/SqlStore.php
@@ -14,6 +14,7 @@
 use Wikibase\DataModel\Services\Lookup\EntityRedirectLookup;
 use Wikibase\Lib\Reporting\ObservableMessageReporter;
 use Wikibase\Lib\Store\CachingEntityRevisionLookup;
+use Wikibase\Lib\Store\ChangeLookup;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -140,6 +141,11 @@
        private $idBlacklist;
 
        /**
+        * @var string[]
+        */
+       private $changeHandlerClasses;
+
+       /**
         * @param EntityContentDataCodec $contentCodec
         * @param EntityIdParser $entityIdParser
         * @param EntityIdLookup $entityIdLookup
@@ -163,6 +169,7 @@
                $this->cacheType = $settings->getSetting( 'sharedCacheType' );
                $this->cacheDuration = $settings->getSetting( 
'sharedCacheDuration' );
                $this->idBlacklist = $settings->getSetting( 'idBlacklist' );
+               $this->changeHandlerClasses = $settings->getSetting( 
'changeHandlers' );
        }
 
        /**
@@ -771,4 +778,13 @@
                return $this->entityPrefetcher;
        }
 
+       /**
+        * @since 0.5
+        *
+        * @return ChangeLookup
+        */
+       public function getChangeLookup() {
+               return new ChangeLookup( $this->changeHandlerClasses );
+       }
+
 }
diff --git a/repo/maintenance/dispatchChanges.php 
b/repo/maintenance/dispatchChanges.php
index 71b1316..ab958e1 100644
--- a/repo/maintenance/dispatchChanges.php
+++ b/repo/maintenance/dispatchChanges.php
@@ -7,6 +7,7 @@
 use MWException;
 use Wikibase\Lib\Reporting\ObservableMessageReporter;
 use Wikibase\Lib\Reporting\ReportingExceptionHandler;
+use Wikibase\Lib\Store\ChangeLookup;
 use Wikibase\Lib\Store\SiteLinkTable;
 use Wikibase\Repo\ChangeDispatcher;
 use Wikibase\Repo\Notifications\JobQueueChangeNotificationSender;
@@ -65,14 +66,13 @@
        /**
         * Initializes members from command line options and configuration 
settings.
         *
+        * @param ChangeLookup $changeLookup
         * @param SettingsArray $settings
         *
         * @return ChangeDispatcher
         * @throws MWException
         */
-       private function newChangeDispatcher( SettingsArray $settings ) {
-               $changesTable = new ChangesTable(); //TODO: allow injection of 
a mock instance for testing
-
+       private function newChangeDispatcher( ChangeLookup $changeLookup, 
SettingsArray $settings ) {
                $repoDB = $settings->getSetting( 'changesDatabase' );
                $clientWikis = $settings->getSetting( 'localClientDatabases' );
                $batchChunkFactor = $settings->getSetting( 
'dispatchBatchChunkFactor' );
@@ -89,7 +89,7 @@
 
                $cacheChunkSize = $batchSize * $batchChunkFactor;
                $cacheSize = $cacheChunkSize * $batchCacheFactor;
-               $changesCache = new ChunkCache( $changesTable, $cacheChunkSize, 
$cacheSize );
+               $changesCache = new ChunkCache( $changeLookup, $cacheChunkSize, 
$cacheSize );
 
                // make sure we have a mapping from siteId to database name in 
clientWikis:
                foreach ( $clientWikis as $siteID => $dbName ) {
@@ -157,8 +157,11 @@
                $maxPasses = (int)$this->getOption( 'max-passes', $maxTime < 
PHP_INT_MAX ? PHP_INT_MAX : 1 );
                $delay = (int)$this->getOption( 'idle-delay', 10 );
 
-               $settings = WikibaseRepo::getDefaultInstance()->getSettings();
-               $dispatcher = $this->newChangeDispatcher( $settings );
+               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $dispatcher = $this->newChangeDispatcher(
+                       $wikibaseRepo->getStore()->getChangeLookup(),
+                       $wikibaseRepo->getSettings()
+               );
 
                $dispatcher->getDispatchCoordinator()->initState();
 
diff --git 
a/repo/tests/phpunit/includes/Notifications/DatabaseChangeTransmitterTest.php 
b/repo/tests/phpunit/includes/Notifications/DatabaseChangeTransmitterTest.php
index 129471c..44c991f 100644
--- 
a/repo/tests/phpunit/includes/Notifications/DatabaseChangeTransmitterTest.php
+++ 
b/repo/tests/phpunit/includes/Notifications/DatabaseChangeTransmitterTest.php
@@ -94,18 +94,15 @@
         * @dataProvider transmitChangeProvider
         */
        public function testTransmitChange( array $expected, EntityChange 
$change ) {
-               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-
                $db = wfGetDB( DB_MASTER );
-               $tableName = 
$wikibaseRepo->getStore()->getChangesTable()->getName();
 
-               $db->delete( $tableName, '*', __METHOD__ );
-               $this->tablesUsed[] = $tableName;
+               $db->delete( 'wb_changes', '*', __METHOD__ );
+               $this->tablesUsed[] = 'wb_changes';
 
                $channel = new DatabaseChangeTransmitter( wfGetLB() );
                $channel->transmitChange( $change );
 
-               $res = $db->select( $tableName, '*', array(), __METHOD__ );
+               $res = $db->select( 'wb_changes', '*', array(), __METHOD__ );
 
                $this->assertEquals( 1, $res->numRows(), 'row count' );
 
diff --git a/repo/tests/phpunit/includes/store/StoreTest.php 
b/repo/tests/phpunit/includes/store/StoreTest.php
index e46074c..ce04f17 100644
--- a/repo/tests/phpunit/includes/store/StoreTest.php
+++ b/repo/tests/phpunit/includes/store/StoreTest.php
@@ -77,4 +77,12 @@
                $this->assertInstanceOf( '\Wikibase\IdGenerator', 
$store->newIdGenerator() );
        }
 
+       /**
+        * @dataProvider instanceProvider
+        * @param Store $store
+        */
+       public function testGetChangeLookup( Store $store ) {
+               $this->assertInstanceOf( '\Wikibase\Lib\Store\ChangeLookup', 
$store->getChangeLookup() );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/244513
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I02189fbfdfc22fa58ca46f5af7c153e24d04b1dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to