Aude has uploaded a new change for review.

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

Change subject: Access SiteSQLStore (memcached) once or twice in the client
......................................................................

Access SiteSQLStore (memcached) once or twice in the client

before these patches, it was accessed ~18 times for me,
when purging page, but now it is 1-2 times.

there still are some places that use WikibaseClient::getSite,
which involves extra access to SiteStore. Due to in process
caching, changing this to use the cached SiteList interferes
with tests so didn't change that here.

Change-Id: If66078ac7e0a6ec63ff618fa86be32868e9127b0
---
M client/includes/WikibaseClient.php
M client/includes/hooks/OtherProjectsSidebarGenerator.php
M client/tests/phpunit/includes/hooks/OtherProjectsSidebarGeneratorTest.php
M client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
4 files changed, 37 insertions(+), 13 deletions(-)


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

diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 7315fa5..449374c 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -11,6 +11,7 @@
 use MediaWikiSite;
 use MWException;
 use Site;
+use SiteList;
 use SiteSQLStore;
 use SiteStore;
 use ValueFormatters\FormatterOptions;
@@ -123,6 +124,11 @@
         * @var OutputFormatValueFormatterFactory
         */
        private $valueFormatterFactory;
+
+       /**
+        * @var SiteList
+        */
+       private $siteList = null;
 
        /**
         * @var SiteStore
@@ -538,7 +544,7 @@
                                $this->getNamespaceChecker(),
                                $this->getStore()->getSiteLinkTable(),
                                $this->getStore()->getEntityLookup(),
-                               $this->getSiteStore()->getSites(),
+                               $this->getSiteList(),
                                $this->getLangLinkSiteGroup()
                        );
                }
@@ -559,6 +565,17 @@
                        is_array( $badgeClassNames ) ? $badgeClassNames : 
array(),
                        $wgLang
                );
+       }
+
+       /**
+        * @return SiteList
+        */
+       public function getSiteList() {
+               if ( $this->siteList === null ) {
+                       $this->siteList = $this->getSiteStore()->getSites();
+               }
+
+               return $this->siteList;
        }
 
        /**
@@ -648,7 +665,7 @@
                return new OtherProjectsSidebarGenerator(
                        $settings->getSetting( 'siteGlobalID' ),
                        $this->getStore()->getSiteLinkTable(),
-                       $this->getSiteStore(),
+                       $this->getSiteList(),
                        $settings->getSetting( 'otherProjectsLinks' )
                );
        }
@@ -716,9 +733,12 @@
         * @return OtherProjectsSitesProvider
         */
        public function getOtherProjectsSitesProvider() {
+               $siteList = $this->getSiteList();
+               $siteId = $this->getSettings()->getSetting( 'siteGlobalID' );
+
                return new OtherProjectsSitesProvider(
-                       $this->getSiteStore()->getSites(),
-                       $this->getSite(),
+                       $siteList,
+                       $siteList->getSite( $siteId ),
                        $this->getSettings()->getSetting( 
'specialSiteLinkGroups' )
                );
        }
diff --git a/client/includes/hooks/OtherProjectsSidebarGenerator.php 
b/client/includes/hooks/OtherProjectsSidebarGenerator.php
index 8cb5c6d..b2bfc63 100644
--- a/client/includes/hooks/OtherProjectsSidebarGenerator.php
+++ b/client/includes/hooks/OtherProjectsSidebarGenerator.php
@@ -3,7 +3,7 @@
 namespace Wikibase\Client\Hooks;
 
 use Site;
-use SiteStore;
+use SiteList;
 use Title;
 use Wikibase\DataModel\SiteLink;
 use Wikibase\Lib\Store\SiteLinkLookup;
@@ -29,9 +29,9 @@
        private $siteLinkLookup;
 
        /**
-        * @var SiteStore
+        * @var SiteList
         */
-       private $siteStore;
+       private $siteList;
 
        /**
         * @var string[]
@@ -41,13 +41,15 @@
        /**
         * @param string $localSiteId
         * @param SiteLinkLookup $siteLinkLookup
-        * @param SiteStore $siteStore
+        * @param SiteList $sites
         * @param string[] $siteIdsToOutput
         */
-       public function __construct( $localSiteId, SiteLinkLookup 
$siteLinkLookup, SiteStore $siteStore, array $siteIdsToOutput ) {
+       public function __construct( $localSiteId, SiteLinkLookup 
$siteLinkLookup, SiteList $sites,
+               array $siteIdsToOutput
+       ) {
                $this->localSiteId = $localSiteId;
                $this->siteLinkLookup = $siteLinkLookup;
-               $this->siteStore = $siteStore;
+               $this->sites = $sites;
                $this->siteIdsToOutput = $siteIdsToOutput;
        }
 
@@ -72,7 +74,7 @@
                        if ( !in_array( $siteLink->getSiteId(), 
$this->siteIdsToOutput ) ) {
                                continue;
                        }
-                       $site = $this->siteStore->getSite( 
$siteLink->getSiteId() );
+                       $site = $this->sites->getSite( $siteLink->getSiteId() );
                        if ( $site === null ) {
                                continue;
                        }
diff --git 
a/client/tests/phpunit/includes/hooks/OtherProjectsSidebarGeneratorTest.php 
b/client/tests/phpunit/includes/hooks/OtherProjectsSidebarGeneratorTest.php
index a9a34bc..8d319cf 100644
--- a/client/tests/phpunit/includes/hooks/OtherProjectsSidebarGeneratorTest.php
+++ b/client/tests/phpunit/includes/hooks/OtherProjectsSidebarGeneratorTest.php
@@ -33,10 +33,12 @@
                $mockRepo = new MockRepository();
                $mockRepo->putEntity( $item );
 
+               $siteStore = MockSiteStore::newFromTestSites();
+
                $otherProjectSidebarGenerator = new 
OtherProjectsSidebarGenerator(
                        'enwiki',
                        $mockRepo,
-                       MockSiteStore::newFromTestSites(),
+                       $siteStore->getSites(),
                        $siteIdsToOutput
                );
 
diff --git a/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php 
b/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
index 588e78f..43ab4e6 100644
--- a/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
+++ b/client/tests/phpunit/includes/hooks/SidebarHookHandlersTest.php
@@ -195,7 +195,7 @@
                $otherProjectsSidebarGenerator = new 
OtherProjectsSidebarGenerator(
                        $siteId,
                        $mockRepo,
-                       $siteStore,
+                       $siteStore->getSites(),
                        $otherProjectIds
                );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If66078ac7e0a6ec63ff618fa86be32868e9127b0
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