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 <benestar.wikime...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits