Aude has submitted this change and it was merged.

Change subject: (Bug 47288) Use EntityUsageIndex on the client.
......................................................................


(Bug 47288) Use EntityUsageIndex on the client.

This also overhauls the way the SiteLinkTable is used, for
consistency.

Change-Id: Ide20d01f2c38047e6a640f1b3910df3b3cc9e69a
---
M client/includes/ChangeHandler.php
M client/includes/WikibaseLibrary.php
M client/includes/parserhooks/NoLangLinkHandler.php
M client/includes/parserhooks/PropertyParserFunction.php
M client/includes/store/ClientStore.php
M client/includes/store/sql/CachingSqlStore.php
M client/includes/store/sql/DirectSqlStore.php
M client/tests/phpunit/includes/ChangeHandlerTest.php
M lib/tests/phpunit/store/EntityUsageIndexTest.php
M lib/tests/phpunit/store/SiteLinkLookupTest.php
10 files changed, 154 insertions(+), 28 deletions(-)

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



diff --git a/client/includes/ChangeHandler.php 
b/client/includes/ChangeHandler.php
index 0df9c64..3f3a627 100644
--- a/client/includes/ChangeHandler.php
+++ b/client/includes/ChangeHandler.php
@@ -108,7 +108,7 @@
 
        public function __construct( PageUpdater $updater = null,
                        EntityLookup $entityLookup = null,
-                       SiteLinkLookup $siteLinkLookup = null,
+                       EntityUsageIndex $entityUsageIndex = null,
                        \Site $localSite = null ) {
 
                wfProfileIn( __METHOD__ );
@@ -123,8 +123,8 @@
                        $entityLookup = 
WikibaseClient::getDefaultInstance()->getStore()->getEntityLookup();
                }
 
-               if ( !$siteLinkLookup ) {
-                       $siteLinkLookup = 
WikibaseClient::getDefaultInstance()->getStore()->newSiteLinkTable();
+               if ( !$entityUsageIndex ) {
+                       $entityUsageIndex = 
WikibaseClient::getDefaultInstance()->getStore()->getEntityUsageIndex();
                }
 
                if ( !$localSite ) {
@@ -140,7 +140,7 @@
                $this->site = $localSite;
                $this->updater = $updater;
                $this->entityLookup = $entityLookup;
-               $this->siteLinkLookup = $siteLinkLookup;
+               $this->entityUsageIndex = $entityUsageIndex;
 
                // TODO: allow these to be passed in as parameters!
                $this->setNamespaces(
@@ -549,15 +549,12 @@
                if ( $change instanceof ItemChange ) {
                        // update local pages connected to a relevant data item.
 
-                       $itemId = $change->getEntityId()->getNumericId();
+                       $itemId = $change->getEntityId();
 
                        $siteGlobalId = $this->site->getGlobalId();
 
-                       // @todo: getLinks is a bit ugly, need a getter for a 
pair of item id + site key
-                       $siteLinks = $this->siteLinkLookup->getLinks( array( 
$itemId ), array( $siteGlobalId ) );
-                       if ( !empty( $siteLinks ) ) {
-                               $pagesToUpdate[] = $siteLinks[0][1];
-                       }
+                       $usedOnPages = $this->entityUsageIndex->getEntityUsage( 
array( $itemId ) );
+                       $pagesToUpdate = array_merge( $pagesToUpdate, 
$usedOnPages );
 
                        // if an item's sitelinks change, update the old and 
the new target
                        $siteLinkDiff = ( $change instanceof ItemChange ) ? 
$change->getSiteLinkDiff() : null;
diff --git a/client/includes/WikibaseLibrary.php 
b/client/includes/WikibaseLibrary.php
index 96eb9bb..8039c60 100644
--- a/client/includes/WikibaseLibrary.php
+++ b/client/includes/WikibaseLibrary.php
@@ -94,7 +94,7 @@
        public function getEntityId( $pageTitle = null ) {
                $this->checkType( 'getEntityByTitle', 1, $pageTitle, 'string' );
                $globalSiteId = \Wikibase\Settings::get( 'siteGlobalID' );
-               $table = WikibaseClient::getDefaultInstance()->getStore( 
'sqlstore' )->newSiteLinkTable();
+               $table = 
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable();
                if ( $table == null ) {
                        return array( null );
                }
diff --git a/client/includes/parserhooks/NoLangLinkHandler.php 
b/client/includes/parserhooks/NoLangLinkHandler.php
index 9008e36..e81608d 100644
--- a/client/includes/parserhooks/NoLangLinkHandler.php
+++ b/client/includes/parserhooks/NoLangLinkHandler.php
@@ -48,7 +48,7 @@
                        Settings::get( 'siteGlobalID' ),
                        Settings::get( 'namespaces' ),
                        Settings::get( 'excludeNamespaces' ),
-                       
WikibaseClient::getDefaultInstance()->getStore()->newSiteLinkTable(),
+                       
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable(),
                        \Sites::singleton()
                );
 
diff --git a/client/includes/parserhooks/PropertyParserFunction.php 
b/client/includes/parserhooks/PropertyParserFunction.php
index 097fafd..bd1a9e4 100644
--- a/client/includes/parserhooks/PropertyParserFunction.php
+++ b/client/includes/parserhooks/PropertyParserFunction.php
@@ -160,8 +160,8 @@
                wfProfileIn( __METHOD__ );
                $site = \Sites::singleton()->getSite( Settings::get( 
'siteGlobalID' ) );
 
-               $siteLinkLookup = 
WikibaseClient::getDefaultInstance()->getStore()->newSiteLinkTable();
-               $entityId = $siteLinkLookup->getEntityIdForSiteLink(
+               $siteLinkLookup = 
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable();
+               $entityId = $siteLinkLookup->getEntityIdForSiteLink( //FIXME: 
method not in the interface
                        new SiteLink( $site, $parser->getTitle()->getFullText() 
)
                );
 
diff --git a/client/includes/store/ClientStore.php 
b/client/includes/store/ClientStore.php
index c8399dc..8ed355d 100644
--- a/client/includes/store/ClientStore.php
+++ b/client/includes/store/ClientStore.php
@@ -34,13 +34,22 @@
 interface ClientStore {
 
        /**
-        * Returns a new SiteLinkLookup for this store.
+        * Returns a SiteLinkLookup for this store.
         *
-        * @since 0.1
+        * @since 0.4
         *
         * @return SiteLinkLookup
         */
-       public function newSiteLinkTable();
+       public function getSiteLinkTable();
+
+       /**
+        * Returns a EntityUsageIndex for this store.
+        *
+        * @since 0.4
+        *
+        * @return EntityUsageIndex
+        */
+       public function getEntityUsageIndex();
 
        /**
         * Returns a new EntityLookup for this store.
@@ -48,8 +57,6 @@
         * @since 0.1
         *
         * @return EntityLookup
-        *
-        * @todo: rename to newEntityMirror
         */
        public function getEntityLookup();
 
diff --git a/client/includes/store/sql/CachingSqlStore.php 
b/client/includes/store/sql/CachingSqlStore.php
index 5a5b133..919d006 100644
--- a/client/includes/store/sql/CachingSqlStore.php
+++ b/client/includes/store/sql/CachingSqlStore.php
@@ -59,13 +59,71 @@
        }
 
        /**
-        * @see Store::newSiteLinkTable
+        * @var SiteLinkTable
+        */
+       private $siteLinkTable = null;
+
+       /**
+        * @var EntityUsageIndex
+        */
+       private $entityUsageIndex = null;
+
+       /**
+        * @see Store::getEntityUsageIndex
         *
+        * @since 0.4
+        *
+        * @return EntityUsageIndex
+        */
+       public function getEntityUsageIndex() {
+               if ( !$this->entityUsageIndex ) {
+                       $this->entityUsageIndex = $this->newEntityUsageIndex();
+               }
+
+               return $this->siteLinkTable;
+       }
+
+       /**
+        * @since 0.4
+        *
+        * @return SiteLinkLookup
+        */
+       protected function newEntityUsageIndex() {
+               return new EntityUsageIndex( $this->getSite(), 
$this->getSiteLinkTable() );
+       }
+
+       /**
+        * @todo ClientStoreFactory should be factored into WikibaseClient, so 
WikibaseClient
+        *       can inject info like the wiki's Site object into the 
ClientStore instance.
+        *
+        * @return null|\Site
+        */
+       private function getSite() {
+               $site = \Sites::singleton()->getSite( Settings::get( 
'siteGlobalID' ) );
+               return $site;
+       }
+
+       /**
+        * @see Store::getSiteLinkTable
+        *
+        * @since 0.4
+        *
+        * @return SiteLinkLookup
+        */
+       public function getSiteLinkTable() {
+               if ( !$this->siteLinkTable ) {
+                       $this->siteLinkTable = $this->newSiteLinkTable();
+               }
+
+               return $this->siteLinkTable;
+       }
+
+       /**
         * @since 0.3
         *
         * @return SiteLinkLookup
         */
-       public function newSiteLinkTable() {
+       protected function newSiteLinkTable() {
                return new SiteLinkTable( 'wbc_items_per_site', true );
        }
 
diff --git a/client/includes/store/sql/DirectSqlStore.php 
b/client/includes/store/sql/DirectSqlStore.php
index 28c3629..4596948 100644
--- a/client/includes/store/sql/DirectSqlStore.php
+++ b/client/includes/store/sql/DirectSqlStore.php
@@ -62,6 +62,16 @@
        protected $language;
 
        /**
+        * @var SiteLinkTable
+        */
+       private $siteLinkTable = null;
+
+       /**
+        * @var EntityUsageIndex
+        */
+       private $entityUsageIndex = null;
+
+       /**
         * @param Language $wikiLanguage
         * @param string    $repoWiki the symbolic database name of the repo 
wiki
         */
@@ -71,13 +81,58 @@
        }
 
        /**
-        * @see Store::newSiteLinkTable
+        * @see Store::getEntityUsageIndex
         *
+        * @since 0.4
+        *
+        * @return EntityUsageIndex
+        */
+       public function getEntityUsageIndex() {
+               if ( !$this->entityUsageIndex ) {
+                       $this->entityUsageIndex = $this->newEntityUsageIndex();
+               }
+
+               return $this->siteLinkTable;
+       }
+
+       /**
+        * @since 0.4
+        *
+        * @return EntityUsageIndex
+        */
+       protected function newEntityUsageIndex() {
+               return new EntityUsageIndex( $this->getSite(), 
$this->getSiteLinkTable() );
+       }
+
+       /**
+        * @return null|\Site
+        */
+       private function getSite() {
+               $site = \Sites::singleton()->getSite( Settings::get( 
'siteGlobalID' ) );
+               return $site;
+       }
+
+       /**
+        * @see Store::getSiteLinkTable
+        *
+        * @since 0.4
+        *
+        * @return SiteLinkLookup
+        */
+       public function getSiteLinkTable() {
+               if ( !$this->siteLinkTable ) {
+                       $this->siteLinkTable = $this->newSiteLinkTable();
+               }
+
+               return $this->siteLinkTable;
+       }
+
+       /**
         * @since 0.3
         *
         * @return SiteLinkLookup
         */
-       public function newSiteLinkTable() {
+       protected function newSiteLinkTable() {
                return new SiteLinkTable( 'wb_items_per_site', true, 
$this->repoWiki );
        }
 
diff --git a/client/tests/phpunit/includes/ChangeHandlerTest.php 
b/client/tests/phpunit/includes/ChangeHandlerTest.php
index 2038e2a..9a74c14 100644
--- a/client/tests/phpunit/includes/ChangeHandlerTest.php
+++ b/client/tests/phpunit/includes/ChangeHandlerTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Test;
 use Wikibase\ChangeHandler;
+use Wikibase\EntityUsageIndex;
 use Wikibase\Item;
 use Wikibase\Property;
 use Wikibase\EntityChange;
@@ -45,11 +46,15 @@
 
                $this->site = \Sites::singleton()->getSite( 'enwiki' );
 
+               $repo = self::getMockRepo();
+               $usageIndex = new EntityUsageIndex( $this->site, $repo );
+
                $this->updater = new MockPageUpdater();
-               $this->handler = new ChangeHandler( $this->updater,
-                                       self::getMockRepo(),
-                                       self::getMockRepo(),
-                                       $this->site );
+               $this->handler = new ChangeHandler(
+                       $this->updater,
+                       $repo,
+                       $usageIndex,
+                       $this->site );
 
                $this->handler->setNamespaces( array( NS_MAIN ) );
                $this->handler->setCheckPageExistence( false );
diff --git a/lib/tests/phpunit/store/EntityUsageIndexTest.php 
b/lib/tests/phpunit/store/EntityUsageIndexTest.php
index daaa85b..de1f023 100644
--- a/lib/tests/phpunit/store/EntityUsageIndexTest.php
+++ b/lib/tests/phpunit/store/EntityUsageIndexTest.php
@@ -33,6 +33,10 @@
  * @ingroup WikibaseLib
  * @ingroup Test
  *
+ * @group Wikibase
+ * @group WikibaseLib
+ * @group WikibaseStore
+ *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
  */
diff --git a/lib/tests/phpunit/store/SiteLinkLookupTest.php 
b/lib/tests/phpunit/store/SiteLinkLookupTest.php
index b52db7b..e40c111 100644
--- a/lib/tests/phpunit/store/SiteLinkLookupTest.php
+++ b/lib/tests/phpunit/store/SiteLinkLookupTest.php
@@ -47,7 +47,7 @@
                }
 
                if ( defined( 'WBC_VERSION' ) ) {
-                       $instances[] = 
WikibaseClient::getDefaultInstance()->getStore( 'sqlstore' 
)->newSiteLinkTable();
+                       $instances[] = 
WikibaseClient::getDefaultInstance()->getStore( 'sqlstore' 
)->getSiteLinkTable();
                }
 
                if ( empty( $instances ) ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ide20d01f2c38047e6a640f1b3910df3b3cc9e69a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to