jenkins-bot has submitted this change and it was merged.

Change subject: Update Wikidata - fix for change dispatcher
......................................................................


Update Wikidata - fix for change dispatcher

stop putting unused statement diffs in wb_changes,
which is causing unnecesary performance impact on
the change dispatcher (and also in the clients, when
handling changes there)

Change-Id: I490d15655841f644608fe2b1572f005c4d890d5f
---
M composer.lock
M extensions/Wikibase/lib/includes/changes/EntityChangeFactory.php
M extensions/Wikibase/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
M vendor/composer/installed.json
4 files changed, 121 insertions(+), 27 deletions(-)

Approvals:
  Aude: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/composer.lock b/composer.lock
index d8d5828..42f4159 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1379,7 +1379,7 @@
             "source": {
                 "type": "git",
                 "url": 
"https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase";,
-                "reference": "27dc06de687582e3c0de5207ea79511703861eee"
+                "reference": "fd1f82818ea4fa015d5ae41a12add45387979b75"
             },
             "require": {
                 "data-values/common": "~0.3.0",
@@ -1461,7 +1461,7 @@
                 "issues": "https://phabricator.wikimedia.org/";,
                 "irc": "irc://irc.freenode.net/wikidata"
             },
-            "time": "2015-08-31 13:16:41"
+            "time": "2015-09-01 16:20:19"
         },
         {
             "name": "wikibase/wikimedia-badges",
diff --git a/extensions/Wikibase/lib/includes/changes/EntityChangeFactory.php 
b/extensions/Wikibase/lib/includes/changes/EntityChangeFactory.php
index 06d9638..20b186a 100644
--- a/extensions/Wikibase/lib/includes/changes/EntityChangeFactory.php
+++ b/extensions/Wikibase/lib/includes/changes/EntityChangeFactory.php
@@ -8,6 +8,7 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Services\Diff\EntityDiffer;
+use Wikibase\DataModel\Statement\StatementList;
 use Wikibase\EntityChange;
 use Wikibase\EntityFactory;
 
@@ -131,6 +132,11 @@
                        $theEntity = $newEntity;
                }
 
+               // don't include statements diff, since those are unused and 
not helpful
+               // performance-wise to the dispatcher and change handling.
+               $oldEntity->setStatements( new StatementList() );
+               $newEntity->setStatements( new StatementList() );
+
                $diff = $this->entityDiffer->diffEntities( $oldEntity, 
$newEntity );
 
                /**
diff --git 
a/extensions/Wikibase/lib/tests/phpunit/changes/EntityChangeFactoryTest.php 
b/extensions/Wikibase/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
index f64e4ec..80530d8 100644
--- a/extensions/Wikibase/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
+++ b/extensions/Wikibase/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
@@ -2,6 +2,9 @@
 
 namespace Wikibase\Lib\Test\Change;
 
+use Diff\DiffOp\Diff\Diff;
+use Diff\DiffOp\DiffOpAdd;
+use Diff\DiffOp\DiffOpRemove;
 use Wikibase\ChangesTable;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
@@ -10,6 +13,10 @@
 use Wikibase\DataModel\Entity\Property;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Services\Diff\EntityDiffer;
+use Wikibase\DataModel\SiteLink;
+use Wikibase\DataModel\Snak\PropertyNoValueSnak;
+use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Statement\StatementList;
 use Wikibase\EntityChange;
 use Wikibase\EntityFactory;
 use Wikibase\Lib\Changes\EntityChangeFactory;
@@ -26,6 +33,7 @@
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
+ * @author Katie Filbert < aude.w...@gmail.com >
  */
 class EntityChangeFactoryTest extends \PHPUnit_Framework_TestCase {
 
@@ -78,38 +86,118 @@
                $this->assertEquals( $entityId, $change->getEntityId() );
        }
 
-       public function newFromUpdateProvider() {
-               $item1 = new Item( new ItemId( 'Q1' ) );
-               $item2 = new Item( new ItemId( 'Q2' ) );
+       public function testNewFromUpdate() {
+               $itemId = new ItemId( 'Q1' );
 
-               $prop1 = Property::newFromType( 'string' );
-               $prop1->setId( new PropertyId( 'P1' ) );
+               $item = new Item( $itemId );
+               $item->setLabel( 'en', 'kitten' );
 
-               return array(
-                       'add item' => array( EntityChange::ADD, null, $item1, 
'wikibase-item~add' ),
-                       'update item' => array( EntityChange::UPDATE, $item1, 
$item2, 'wikibase-item~update' ),
-                       'remove property' => array( EntityChange::REMOVE, 
$prop1, null, 'wikibase-property~remove' ),
+               $updatedItem = new Item( $itemId );
+               $updatedItem->setLabel( 'en', 'kitten' );
+               $updatedItem->setLabel( 'es', 'gato' );
+
+               $factory = $this->getEntityChangeFactory();
+
+               $change = $factory->newFromUpdate( EntityChange::UPDATE, $item, 
$updatedItem );
+
+               $this->assertEquals( $itemId, $change->getEntityId(), 'entity 
id' );
+               $this->assertEquals( 'q1', $change->getObjectId(), 'object id' 
);
+               $this->assertEquals( 'wikibase-item~update', 
$change->getType(), 'type' );
+
+               $this->assertEquals(
+                       new Diff( array( 'es' => new DiffOpAdd( 'gato' ) ) ),
+                       $change->getDiff()->getLabelsDiff(),
+                       'diff'
                );
        }
 
-       /**
-        * @dataProvider newFromUpdateProvider
-        *
-        * @param string $action
-        * @param Entity $oldEntity
-        * @param Entity $newEntity
-        * @param string $expectedType
-        */
-       public function testNewFromUpdate( $action, $oldEntity, $newEntity, 
$expectedType ) {
+       public function testNewFromUpdate_add() {
+               $itemId = new ItemId( 'Q1' );
+
+               $item = new Item( $itemId );
+               $item->setLabel( 'en', 'kitten' );
+
+               $factory = $this->getEntityChangeFactory();
+               $change = $factory->newFromUpdate( EntityChange::ADD, null, 
$item );
+
+               $this->assertEquals( $itemId, $change->getEntityId(), 'entity 
id' );
+               $this->assertEquals( 'q1', $change->getObjectId(), 'object id' 
);
+               $this->assertEquals( 'wikibase-item~add', $change->getType(), 
'type' );
+
+               $this->assertEquals(
+                       new Diff( array( 'en' => new DiffOpAdd( 'kitten' ) ) ),
+                       $change->getDiff()->getLabelsDiff(),
+                       'diff'
+               );
+       }
+
+       public function testNewFromUpdate_remove() {
+               $propertyId = new PropertyId( 'P2' );
+
+               $property = new Property( $propertyId, null, 'string' );
+               $property->setLabel( 'de', 'Katze' );
+
+               $factory = $this->getEntityChangeFactory();
+               $change = $factory->newFromUpdate( EntityChange::REMOVE, 
$property, null );
+
+               $this->assertEquals( $propertyId, $change->getEntityId(), 
'entity id' );
+               $this->assertEquals( 'p2', $change->getObjectId(), 'object id' 
);
+               $this->assertEquals( 'wikibase-property~remove', 
$change->getType(), 'type' );
+
+               $this->assertEquals(
+                       new Diff( array( 'de' => new DiffOpRemove( 'Katze' ) ) 
),
+                       $change->getDiff()->getLabelsDiff(),
+                       'diff'
+               );
+       }
+
+       public function testNewFromUpdate_restore() {
+               $itemId = new ItemId( 'Q4' );
+
+               $item = new Item( $itemId );
+               $item->addSiteLink( new SiteLink( 'enwiki', 'Kitten' ) );
+
+               $factory = $this->getEntityChangeFactory();
+               $change = $factory->newFromUpdate( EntityChange::RESTORE, null, 
$item );
+
+               $this->assertEquals( $itemId, $change->getEntityId(), 'entity 
id' );
+               $this->assertEquals( 'q4', $change->getObjectId(), 'object id' 
);
+               $this->assertEquals( 'wikibase-item~restore', 
$change->getType(), 'type' );
+
+               $this->assertEquals(
+                       new Diff( array(
+                               'enwiki' => new Diff( array(
+                                       'name' => new DiffOpAdd( 'Kitten' )
+                               ) )
+                       ) ),
+                       $change->getDiff()->getSiteLinkDiff(),
+                       'diff'
+               );
+       }
+
+       public function testNewFromUpdate_excludeStatementsInDiffs() {
                $factory = $this->getEntityChangeFactory();
 
-               $entityId = ( $newEntity === null ) ? $oldEntity->getId() : 
$newEntity->getId();
+               $item = new Item( new ItemId( 'Q3' ) );
+               $statementList = new StatementList( array(
+                       new Statement( new PropertyNoValueSnak( 9000 ) )
+               ) );
 
-               $change = $factory->newFromUpdate( $action, $oldEntity, 
$newEntity );
+               $item->setStatements( $statementList );
 
-               $this->assertEquals( $action, $change->getAction() );
-               $this->assertEquals( $entityId, $change->getEntityId() );
-               $this->assertEquals( $expectedType, $change->getType() );
+               $updatedItem = new Item( new ItemId( 'Q3' ) );
+               $statementList = new StatementList( array(
+                       new Statement( new PropertyNoValueSnak( 10 ) )
+               ) );
+
+               $updatedItem->setStatements( $statementList );
+
+               $change = $factory->newFromUpdate( EntityChange::UPDATE, $item, 
$updatedItem );
+
+               $this->assertTrue(
+                       $change->getDiff()->isEmpty(),
+                       'Diff excludes statement changes and is empty'
+               );
        }
 
 }
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 959d555..03fa274 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -1467,7 +1467,7 @@
         "source": {
             "type": "git",
             "url": 
"https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase";,
-            "reference": "27dc06de687582e3c0de5207ea79511703861eee"
+            "reference": "fd1f82818ea4fa015d5ae41a12add45387979b75"
         },
         "require": {
             "data-values/common": "~0.3.0",
@@ -1497,7 +1497,7 @@
         "require-dev": {
             "squizlabs/php_codesniffer": "~2.1"
         },
-        "time": "2015-08-30 19:08:10",
+        "time": "2015-09-01 10:55:48",
         "type": "mediawiki-extension",
         "installation-source": "source",
         "autoload": {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I490d15655841f644608fe2b1572f005c4d890d5f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikidata
Gerrit-Branch: wmf/1.26wmf20
Gerrit-Owner: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to