Hoo man has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/386382 )
Change subject: Use CacheRetrievingEntityRevisionLookup for dumps etc.
......................................................................
Use CacheRetrievingEntityRevisionLookup for dumps etc.
Bug: T178247
Change-Id: I3cc52201cc4de00d9ba971ebdc90eb5dfaf448d2
---
M repo/includes/Store/Sql/SqlStore.php
M repo/includes/Store/Store.php
M repo/includes/WikibaseRepo.php
M repo/maintenance/dumpJson.php
M repo/maintenance/dumpRdf.php
M repo/maintenance/rebuildItemsPerSite.php
M repo/maintenance/rebuildTermSqlIndex.php
M repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
8 files changed, 89 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/82/386382/1
diff --git a/repo/includes/Store/Sql/SqlStore.php
b/repo/includes/Store/Sql/SqlStore.php
index e41e28c..5bb643d 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -15,6 +15,7 @@
use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup;
use Wikibase\Lib\Changes\EntityChangeFactory;
use Wikibase\Lib\EntityIdComposer;
+use Wikibase\Lib\Store\CacheRetrievingEntityRevisionLookup;
use Wikibase\Lib\Store\CachingEntityRevisionLookup;
use Wikibase\Lib\Store\CacheAwarePropertyInfoStore;
use Wikibase\Lib\Store\CachingPropertyInfoLookup;
@@ -83,6 +84,11 @@
* @var EntityRevisionLookup|null
*/
private $rawEntityRevisionLookup = null;
+
+ /**
+ * @var CacheRetrievingEntityRevisionLookup|null
+ */
+ private $cacheRetrievingEntityRevisionLookup = null;
/**
* @var EntityStore|null
@@ -360,12 +366,13 @@
*
* The EntityLookup returned by this method will resolve redirects.
*
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityLookup
*/
- public function getEntityLookup( $uncached = '' ) {
- $revisionLookup = $this->getEntityRevisionLookup( $uncached );
+ public function getEntityLookup( $cache = '' ) {
+ $revisionLookup = $this->getEntityRevisionLookup( $cache );
$revisionBasedLookup = new RevisionBasedEntityLookup(
$revisionLookup );
$resolvingLookup = new RedirectResolvingEntityLookup(
$revisionBasedLookup );
return $resolvingLookup;
@@ -412,20 +419,31 @@
/**
* @see Store::getEntityRevisionLookup
*
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityRevisionLookup
*/
- public function getEntityRevisionLookup( $uncached = '' ) {
+ public function getEntityRevisionLookup( $cache = '' ) {
if ( !$this->entityRevisionLookup ) {
list( $this->rawEntityRevisionLookup,
$this->entityRevisionLookup ) = $this->newEntityRevisionLookup();
}
- if ( $uncached === 'uncached' ) {
+ if ( $cache === 'uncached' ) {
return $this->rawEntityRevisionLookup;
+ } elseif ( $cache === 'retrieve-only' ) {
+ return $this->getCacheRetrievingEntityRevisionLookup();
} else {
return $this->entityRevisionLookup;
}
+ }
+
+ /**
+ * @return string
+ */
+ private function getEntityRevisionLookupCacheKey() {
+ // NOTE: Keep cache key in sync with
DirectSqlStore::newEntityRevisionLookup in WikibaseClient
+ return $this->cacheKeyPrefix . ':WikiPageEntityRevisionLookup';
}
/**
@@ -436,9 +454,6 @@
* EntityRevisionLookup.
*/
private function newEntityRevisionLookup() {
- // NOTE: Keep cache key in sync with
DirectSqlStore::newEntityRevisionLookup in WikibaseClient
- $cacheKeyPrefix = $this->cacheKeyPrefix .
':WikiPageEntityRevisionLookup';
-
// Maintain a list of watchers to be notified of changes to any
entities,
// in order to update caches.
/** @var WikiPageEntityStore $dispatcher */
@@ -452,7 +467,7 @@
new EntityRevisionCache(
wfGetCache( $this->cacheType ),
$this->cacheDuration,
- $cacheKeyPrefix
+ $this->getEntityRevisionLookupCacheKey()
),
$nonCachingLookup
);
@@ -473,6 +488,28 @@
}
/**
+ * @return CacheRetrievingEntityRevisionLookup
+ */
+ private function getCacheRetrievingEntityRevisionLookup() {
+ if ( !$this->cacheRetrievingEntityRevisionLookup ) {
+ $cacheRetrievingEntityRevisionLookup = new
CacheRetrievingEntityRevisionLookup(
+ new EntityRevisionCache(
+ wfGetCache( $this->cacheType ),
+ $this->cacheDuration,
+ $this->getEntityRevisionLookupCacheKey()
+ ),
+ $this->getEntityRevisionLookup( 'uncached' )
+ );
+
+
$cacheRetrievingEntityRevisionLookup->setVerifyRevision( true );
+
+ $this->cacheRetrievingEntityRevisionLookup =
$cacheRetrievingEntityRevisionLookup;
+ }
+
+ return $this->cacheRetrievingEntityRevisionLookup;
+ }
+
+ /**
* @see Store::getEntityInfoBuilderFactory
*
* @return EntityInfoBuilderFactory
diff --git a/repo/includes/Store/Store.php b/repo/includes/Store/Store.php
index 2c4c702..4070d6f 100644
--- a/repo/includes/Store/Store.php
+++ b/repo/includes/Store/Store.php
@@ -77,18 +77,20 @@
public function getEntityRedirectLookup();
/**
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityLookup
*/
- public function getEntityLookup( $uncached = '' );
+ public function getEntityLookup( $cache = '' );
/**
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityRevisionLookup
*/
- public function getEntityRevisionLookup( $uncached = '' );
+ public function getEntityRevisionLookup( $cache = '' );
/**
* @return EntityStore
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 326f65c..c08d30a 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -669,12 +669,15 @@
}
/**
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @see Store::getEntityRevisionLookup
+ *
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityRevisionLookup
*/
- public function getEntityRevisionLookup( $uncached = '' ) {
- return $this->getStore()->getEntityRevisionLookup( $uncached );
+ public function getEntityRevisionLookup( $cache = '' ) {
+ return $this->getStore()->getEntityRevisionLookup( $cache );
}
/**
@@ -752,12 +755,15 @@
}
/**
- * @param string $uncached Flag string, set to 'uncached' to get an
uncached direct lookup service.
+ * @see Store::getEntityLookup
+ *
+ * @param string $cache Flag string: Can be set to 'uncached' to get an
uncached direct lookup or to 'retrieve-only' to get a
+ * lookup which reads from the cache, but doesn't store
retrieved entities there. Defaults to a caching lookup.
*
* @return EntityLookup
*/
- public function getEntityLookup( $uncached = '' ) {
- return $this->getStore()->getEntityLookup( $uncached );
+ public function getEntityLookup( $cache = '' ) {
+ return $this->getStore()->getEntityLookup( $cache );
}
/**
diff --git a/repo/maintenance/dumpJson.php b/repo/maintenance/dumpJson.php
index e3bce27..ef93de1 100644
--- a/repo/maintenance/dumpJson.php
+++ b/repo/maintenance/dumpJson.php
@@ -80,7 +80,7 @@
$wikibaseRepo->getEntityNamespaceLookup(),
$wikibaseRepo->getEntityIdParser()
);
- $revisionLookup =
$wikibaseRepo->getEntityRevisionLookup( 'uncached' );
+ $revisionLookup =
$wikibaseRepo->getEntityRevisionLookup( 'retrieve-only' );
$this->setServices(
$sqlEntityIdPagerFactory,
diff --git a/repo/maintenance/dumpRdf.php b/repo/maintenance/dumpRdf.php
index 274bc92..f1e6b1b 100644
--- a/repo/maintenance/dumpRdf.php
+++ b/repo/maintenance/dumpRdf.php
@@ -120,7 +120,7 @@
$wikibaseRepo->getPropertyDataTypeLookup(),
$wikibaseRepo->getValueSnakRdfBuilderFactory(),
$wikibaseRepo->getEntityRdfBuilderFactory(),
- $wikibaseRepo->getEntityRevisionLookup(
'uncached' ),
+ $wikibaseRepo->getEntityRevisionLookup(
'retrieve-only' ),
$wikibaseRepo->getRdfVocabulary(),
$wikibaseRepo->getEntityContentFactory()
);
diff --git a/repo/maintenance/rebuildItemsPerSite.php
b/repo/maintenance/rebuildItemsPerSite.php
index b0933db..b73bf19 100644
--- a/repo/maintenance/rebuildItemsPerSite.php
+++ b/repo/maintenance/rebuildItemsPerSite.php
@@ -49,7 +49,7 @@
$siteLinkTable = new SiteLinkTable( 'wb_items_per_site', false
);
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
// Use an uncached EntityLookup here to avoid memory leaks
- $entityLookup = $wikibaseRepo->getEntityLookup( 'uncached' );
+ $entityLookup = $wikibaseRepo->getEntityLookup( 'retrieve-only'
);
$store = $wikibaseRepo->getStore();
$builder = new ItemsPerSiteBuilder(
$siteLinkTable,
diff --git a/repo/maintenance/rebuildTermSqlIndex.php
b/repo/maintenance/rebuildTermSqlIndex.php
index 7e98be0..9748ecd 100644
--- a/repo/maintenance/rebuildTermSqlIndex.php
+++ b/repo/maintenance/rebuildTermSqlIndex.php
@@ -88,7 +88,7 @@
MediaWikiServices::getInstance()->getDBLoadBalancerFactory(),
$termIndex,
$sqlEntityIdPagerFactory,
- $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
+ $wikibaseRepo->getEntityRevisionLookup( 'retrieve-only'
),
$this->getEntityTypes(),
$this->getOption( 'sleep', 10 )
);
diff --git a/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
b/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
index 12b505a..61a49c3 100644
--- a/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
+++ b/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
@@ -102,8 +102,20 @@
$this->assertInstanceOf( EntityRedirectLookup::class, $service
);
}
- public function testGetEntityLookup() {
- $service = $this->newInstance()->getEntityLookup();
+ public function entityLoookupCacheProvider() {
+ return [
+ [ '' ],
+ [ 'uncached' ],
+ [ 'retrieve-only' ],
+ ];
+ }
+
+ /**
+ * @dataProvider entityLoookupCacheProvider
+ */
+ public function testGetEntityLookup( $type ) {
+ $service = $this->newInstance()->getEntityLookup( $type );
+
$this->assertInstanceOf( EntityLookup::class, $service );
}
@@ -117,8 +129,12 @@
$this->assertInstanceOf( EntityStore::class, $service );
}
- public function testGetEntityRevisionLookup() {
- $service = $this->newInstance()->getEntityRevisionLookup();
+ /**
+ * @dataProvider entityLoookupCacheProvider
+ */
+ public function testGetEntityRevisionLookup( $type ) {
+ $service = $this->newInstance()->getEntityRevisionLookup( $type
);
+
$this->assertInstanceOf( EntityRevisionLookup::class, $service
);
}
--
To view, visit https://gerrit.wikimedia.org/r/386382
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3cc52201cc4de00d9ba971ebdc90eb5dfaf448d2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits