Aude has uploaded a new change for review.

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

Change subject: Don't fetch sites from site store numerous times in 
LangLinkHandler
......................................................................

Don't fetch sites from site store numerous times in LangLinkHandler

instead we can and should inject the SiteList object here.

Change-Id: I31ee539531b69de3d85963bacd4bdd72aba85aff
---
M client/includes/LangLinkHandler.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/LangLinkHandlerTest.php
M client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
4 files changed, 19 insertions(+), 23 deletions(-)


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

diff --git a/client/includes/LangLinkHandler.php 
b/client/includes/LangLinkHandler.php
index af0eceb..aa26a92 100644
--- a/client/includes/LangLinkHandler.php
+++ b/client/includes/LangLinkHandler.php
@@ -4,7 +4,7 @@
 
 use ParserOutput;
 use Site;
-use SiteStore;
+use SiteList;
 use Title;
 use Wikibase\Client\Hooks\LanguageLinkBadgeDisplay;
 use Wikibase\Client\Hooks\OtherProjectsSidebarGenerator;
@@ -59,9 +59,9 @@
        private $entityLookup;
 
        /**
-        * @var SiteStore
+        * @var SiteList
         */
-       private $siteStore;
+       private $sites;
 
        /**
         * @var string
@@ -80,7 +80,7 @@
         * @param NamespaceChecker $namespaceChecker determines which 
namespaces wikibase is enabled on
         * @param SiteLinkLookup $siteLinkLookup A site link lookup service
         * @param EntityLookup $entityLookup An entity lookup service
-        * @param SiteStore $siteStore A site definition lookup service
+        * @param SiteList $sites
         * @param string $siteGroup The ID of the site group to use for showing 
language links.
         */
        public function __construct(
@@ -90,7 +90,7 @@
                NamespaceChecker $namespaceChecker,
                SiteLinkLookup $siteLinkLookup,
                EntityLookup $entityLookup,
-               SiteStore $siteStore,
+               SiteList $sites,
                $siteGroup
        ) {
                $this->otherProjectsSidebarGenerator = 
$otherProjectsSidebarGenerator;
@@ -99,7 +99,7 @@
                $this->namespaceChecker = $namespaceChecker;
                $this->siteLinkLookup = $siteLinkLookup;
                $this->entityLookup = $entityLookup;
-               $this->siteStore = $siteStore;
+               $this->sites = $sites;
                $this->siteGroup = $siteGroup;
        }
 
@@ -175,7 +175,7 @@
 
                foreach ( $links as $link ) {
                        $siteId = $link->getSiteId();
-                       $site = $this->siteStore->getSite( $siteId );
+                       $site = $this->sites->getSite( $siteId );
 
                        if ( !$site ) {
                                continue;
@@ -253,10 +253,8 @@
                                return array();
                        }
 
-                       $siteList = $this->siteStore->getSites();
-
-                       if ( $siteList->hasNavigationId( $code ) ) {
-                               $site = $siteList->getSiteByNavigationId( $code 
);
+                       if ( $this->sites->hasNavigationId( $code ) ) {
+                               $site = $this->sites->getSiteByNavigationId( 
$code );
                                $wiki = $site->getGlobalId();
                                unset( $repoLinks[$wiki] );
                        }
@@ -284,14 +282,14 @@
                wfProfileIn( __METHOD__ );
 
                foreach ( $repoLinks as $wiki => $link ) {
-                       $site = $this->siteStore->getSite( $wiki );
-
-                       if ( $site === null ) {
+                       if ( !$this->sites->hasSite( $wiki ) ) {
                                wfDebugLog( __CLASS__, __FUNCTION__ . ': 
skipping link to unknown site ' . $wiki );
 
                                unset( $repoLinks[$wiki] );
                                continue;
                        }
+
+                       $site = $this->sites->getSite( $wiki );
 
                        if ( !in_array( $site->getGroup(), $allowedGroups ) ) {
                                wfDebugLog( __CLASS__, __FUNCTION__ . ': 
skipping link to other group: ' . $wiki
@@ -342,10 +340,8 @@
                                $lang = $parts[0];
                                $page = $parts[1];
 
-                               $siteList = $this->siteStore->getSites();
-
-                               if ( $siteList->hasNavigationId( $lang ) ) {
-                                       $site = 
$siteList->getSiteByNavigationId( $lang );
+                               if ( $this->sites->hasNavigationId( $lang ) ) {
+                                       $site = 
$this->sites->getSiteByNavigationId( $lang );
                                        $wiki = $site->getGlobalId();
                                        $links[$wiki] = $page;
                                } else {
@@ -433,7 +429,7 @@
        private function addLinksToOutput( array $links, ParserOutput $out ) {
                foreach ( $links as $siteId => $siteLink ) {
                        $page = $siteLink->getPageName();
-                       $targetSite = $this->siteStore->getSite( $siteId );
+                       $targetSite = $this->sites->getSite( $siteId );
 
                        if ( !$targetSite ) {
                                wfLogWarning( "Unknown wiki '$siteId' used as 
sitelink target" );
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 0e11503..7315fa5 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -538,7 +538,7 @@
                                $this->getNamespaceChecker(),
                                $this->getStore()->getSiteLinkTable(),
                                $this->getStore()->getEntityLookup(),
-                               $this->getSiteStore(),
+                               $this->getSiteStore()->getSites(),
                                $this->getLangLinkSiteGroup()
                        );
                }
diff --git a/client/tests/phpunit/includes/LangLinkHandlerTest.php 
b/client/tests/phpunit/includes/LangLinkHandlerTest.php
index 2550958..eb2952f 100644
--- a/client/tests/phpunit/includes/LangLinkHandlerTest.php
+++ b/client/tests/phpunit/includes/LangLinkHandlerTest.php
@@ -73,7 +73,7 @@
                        $this->mockRepo->putEntity( $item );
                }
 
-               $sites = MockSiteStore::newFromTestSites();
+               $siteStore = MockSiteStore::newFromTestSites();
 
                return new LangLinkHandler(
                        $this->getOtherProjectsSidebarGenerator( $otherProjects 
),
@@ -82,7 +82,7 @@
                        new NamespaceChecker( array( NS_TALK ), array() ),
                        $this->mockRepo,
                        $this->mockRepo,
-                       $sites,
+                       $siteStore->getSites(),
                        'wikipedia'
                );
        }
diff --git a/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php 
b/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
index b9d4819..588e78f 100644
--- a/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
+++ b/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
@@ -212,7 +212,7 @@
                        $namespaceChecker,
                        $mockRepo,
                        $mockRepo,
-                       $siteStore,
+                       $siteStore->getSites(),
                        $siteGroup
                );
 

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

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

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

Reply via email to