[MediaWiki-commits] [Gerrit] Cache items found in ClientSiteLinkLookup - change (mediawiki...Wikibase)

2014-05-23 Thread WMDE
Thiemo Mättig (WMDE) has submitted this change and it was merged.

Change subject: Cache items found in ClientSiteLinkLookup
..


Cache items found in ClientSiteLinkLookup

Caches the items which have been found by title in the ClientSiteLinkLookup
in an array and makes it available through the WikibaseClient default
instance. This improves performance a lot.

Change-Id: I0b7477aead578384f3d1331fc984e2ce48bb9e28
---
M client/includes/ClientSiteLinkLookup.php
M client/includes/WikibaseClient.php
2 files changed, 45 insertions(+), 10 deletions(-)

Approvals:
  WikidataJenkins: Verified
  Daniel Kinzler: Looks good to me, approved



diff --git a/client/includes/ClientSiteLinkLookup.php 
b/client/includes/ClientSiteLinkLookup.php
index e08f306..e95ef8d 100644
--- a/client/includes/ClientSiteLinkLookup.php
+++ b/client/includes/ClientSiteLinkLookup.php
@@ -32,6 +32,11 @@
private $entityLookup;
 
/**
+* @var array
+*/
+   private $cachedItems = array();
+
+   /**
 * @param string $localSiteId global id of the client wiki
 * @param SiteLinkLookup $siteLinkLookup
 * @param EntityLookup $entityLookup
@@ -80,23 +85,31 @@
}
 
/**
-* Finds the corresponding item on the repository.
+* Finds the corresponding item on the repository
+* and caches the result in an array.
 *
 * @param Title $title
 *
 * @return Item|null
 */
private function getItem( Title $title ) {
-   $itemId = $this->siteLinkLookup->getItemIdForLink(
-   $this->localSiteId,
-   $title->getPrefixedText()
-   );
+   $prefixedText = $title->getPrefixedText();
 
-   if ( $itemId === null ) {
-   return null;
+   if ( !array_key_exists( $prefixedText, $this->cachedItems ) ) {
+   $itemId = $this->siteLinkLookup->getItemIdForLink(
+   $this->localSiteId,
+   $prefixedText
+   );
+
+   if ( $itemId === null ) {
+   $this->cachedItems[$prefixedText] = null;
+   }
+   else {
+   $this->cachedItems[$prefixedText] = 
$this->entityLookup->getEntity( $itemId );
+   }
}
 
-   return $this->entityLookup->getEntity( $itemId );
+   return $this->cachedItems[$prefixedText];
}
 
 }
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index b293e8a..f7773ed 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -115,6 +115,10 @@
 */
private $namespaceChecker = null;
 
+   /**
+* @var ClientSiteLinkLookup
+*/
+   private $clientSiteLinkLookup = null;
 
/**
 * @since 0.4
@@ -519,7 +523,6 @@
 * @return NamespaceChecker
 */
public function getNamespaceChecker() {
-
if ( !$this->namespaceChecker ) {
$settings = $this->getSettings();
 
@@ -536,7 +539,6 @@
 * @return LangLinkHandler
 */
public function getLangLinkHandler() {
-
if ( !$this->langLinkHandler ) {
$settings = $this->getSettings();
 
@@ -564,4 +566,24 @@
 
return $this->siteStore;
}
+
+   /**
+* @since 0.5
+*
+* @return ClientSiteLinkLookup
+*/
+   public function getClientSiteLinkLookup() {
+   if ( !$this->clientSiteLinkLookup ) {
+   $settings = $this->getSettings();
+
+   $this->clientSiteLinkLookup = new ClientSiteLinkLookup(
+   $settings->getSetting( 'siteGlobalID' ),
+   $this->getEntityLookup(),
+   $this->getStore()->getSiteLinkLookup()
+   );
+   }
+
+   return $this->clientSiteLinkLookup;
+   }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0b7477aead578384f3d1331fc984e2ce48bb9e28
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene 
Gerrit-Reviewer: Addshore 
Gerrit-Reviewer: Aude 
Gerrit-Reviewer: Bene 
Gerrit-Reviewer: Daniel Kinzler 
Gerrit-Reviewer: Hoo man 
Gerrit-Reviewer: Jeroen De Dauw 
Gerrit-Reviewer: Lydia Pintscher 
Gerrit-Reviewer: Thiemo Mättig (WMDE) 
Gerrit-Reviewer: Tobias Gritschacher 
Gerrit-Reviewer: WikidataJenkins 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-com

[MediaWiki-commits] [Gerrit] Cache items found in ClientSiteLinkLookup - change (mediawiki...Wikibase)

2014-05-22 Thread Bene (Code Review)
Bene has uploaded a new change for review.

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

Change subject: Cache items found in ClientSiteLinkLookup
..

Cache items found in ClientSiteLinkLookup

Caches the items which have been found by title in the ClientSiteLinkLookup
in an array and makes it available through the WikibaseClient default
instance. This improves performance a lot.

Change-Id: I0b7477aead578384f3d1331fc984e2ce48bb9e28
---
M client/includes/ClientSiteLinkLookup.php
M client/includes/WikibaseClient.php
2 files changed, 45 insertions(+), 10 deletions(-)


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

diff --git a/client/includes/ClientSiteLinkLookup.php 
b/client/includes/ClientSiteLinkLookup.php
index e08f306..cc20162 100644
--- a/client/includes/ClientSiteLinkLookup.php
+++ b/client/includes/ClientSiteLinkLookup.php
@@ -32,6 +32,11 @@
private $entityLookup;
 
/**
+* @var array
+*/
+   private $cachedItems = array();
+
+   /**
 * @param string $localSiteId global id of the client wiki
 * @param SiteLinkLookup $siteLinkLookup
 * @param EntityLookup $entityLookup
@@ -80,23 +85,31 @@
}
 
/**
-* Finds the corresponding item on the repository.
+* Finds the corresponding item on the repository
+* and caches the result in an array.
 *
 * @param Title $title
 *
 * @return Item|null
 */
private function getItem( Title $title ) {
-   $itemId = $this->siteLinkLookup->getItemIdForLink(
-   $this->localSiteId,
-   $title->getPrefixedText()
-   );
+   $prefixedText = $title->getPrefixedText();
 
-   if ( $itemId === null ) {
-   return null;
+   if ( !isset( $this->cachedItems[$prefixedText] ) ) {
+   $itemId = $this->siteLinkLookup->getItemIdForLink(
+   $this->localSiteId,
+   $prefixedText
+   );
+
+   if ( $itemId === null ) {
+   $this->cachedItems[$prefixedText] = null;
+   }
+   else {
+   $this->cachedItems[$prefixedText] = 
$this->entityLookup->getEntity( $itemId );
+   }
}
 
-   return $this->entityLookup->getEntity( $itemId );
+   return $this->cachedItems[$prefixedText];
}
 
 }
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index b293e8a..f7773ed 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -115,6 +115,10 @@
 */
private $namespaceChecker = null;
 
+   /**
+* @var ClientSiteLinkLookup
+*/
+   private $clientSiteLinkLookup = null;
 
/**
 * @since 0.4
@@ -519,7 +523,6 @@
 * @return NamespaceChecker
 */
public function getNamespaceChecker() {
-
if ( !$this->namespaceChecker ) {
$settings = $this->getSettings();
 
@@ -536,7 +539,6 @@
 * @return LangLinkHandler
 */
public function getLangLinkHandler() {
-
if ( !$this->langLinkHandler ) {
$settings = $this->getSettings();
 
@@ -564,4 +566,24 @@
 
return $this->siteStore;
}
+
+   /**
+* @since 0.5
+*
+* @return ClientSiteLinkLookup
+*/
+   public function getClientSiteLinkLookup() {
+   if ( !$this->clientSiteLinkLookup ) {
+   $settings = $this->getSettings();
+
+   $this->clientSiteLinkLookup = new ClientSiteLinkLookup(
+   $settings->getSetting( 'siteGlobalID' ),
+   $this->getEntityLookup(),
+   $this->getStore()->getSiteLinkLookup()
+   );
+   }
+
+   return $this->clientSiteLinkLookup;
+   }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b7477aead578384f3d1331fc984e2ce48bb9e28
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene 

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