jenkins-bot has submitted this change and it was merged.
Change subject: Change SitesModule to use getDefinitionSummary for cache
invalidation
......................................................................
Change SitesModule to use getDefinitionSummary for cache invalidation
As ResourceLoaderModule::getModifiedHash has been deprecated.
Change-Id: Id1466a2a780c0553b663bf52848ad4ff985fc66f
---
M lib/includes/modules/SitesModule.php
M lib/includes/modules/SitesModuleWorker.php
M lib/tests/phpunit/SitesModuleWorkerTest.php
3 files changed, 29 insertions(+), 31 deletions(-)
Approvals:
Krinkle: Looks good to me, but someone else must approve
Aude: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/modules/SitesModule.php
b/lib/includes/modules/SitesModule.php
index 7ae14fa..fc7c128 100644
--- a/lib/includes/modules/SitesModule.php
+++ b/lib/includes/modules/SitesModule.php
@@ -46,25 +46,16 @@
}
/**
- * @see ResourceLoaderModule::getModifiedHash
+ * @see ResourceLoaderModule::getDefinitionSummary
*
* @param ResourceLoaderContext $context
*
- * @return string
+ * @return array
*/
- public function getModifiedHash( ResourceLoaderContext $context ) {
- return $this->worker->getModifiedHash();
- }
-
- /**
- * @see ResourceLoaderModule::getModifiedTime
- *
- * @param ResourceLoaderContext $context
- *
- * @return int
- */
- public function getModifiedTime( ResourceLoaderContext $context ) {
- return $this->getHashMtime( $context );
+ public function getDefinitionSummary( ResourceLoaderContext $context ) {
+ $summary = parent::getDefinitionSummary( $context );
+ $summary[] = $this->worker->getDefinitionSummary();
+ return $summary;
}
}
diff --git a/lib/includes/modules/SitesModuleWorker.php
b/lib/includes/modules/SitesModuleWorker.php
index 50e335a..0aa2bf7 100644
--- a/lib/includes/modules/SitesModuleWorker.php
+++ b/lib/includes/modules/SitesModuleWorker.php
@@ -196,15 +196,16 @@
}
/**
- * This returns a hash which should change whenever either a relevant
setting
+ * This returns our additions to the default definition summary.
+ * We add a hash which should change whenever either a relevant setting
* or the list of sites changes. Because computing this list is quite
heavy and
* it barely changes, cache that hash for a short bit.
*
- * @see ResourceLoaderModule::getModifiedHash
+ * @see ResourceLoaderModule::getDefinitionSummary
*
- * @return string
+ * @return array
*/
- public function getModifiedHash() {
+ public function getDefinitionSummary() {
$cacheKey = wfMemcKey( 'wikibase-sites-module-modified-hash' );
$hash = $this->cache->get( $cacheKey );
@@ -213,7 +214,9 @@
$this->cache->set( $cacheKey, $hash,
self::SITES_HASH_CACHE_DURATION );
}
- return $hash;
+ return array(
+ 'dataHash' => $hash
+ );
}
}
diff --git a/lib/tests/phpunit/SitesModuleWorkerTest.php
b/lib/tests/phpunit/SitesModuleWorkerTest.php
index 0f38a6a..f45214e 100644
--- a/lib/tests/phpunit/SitesModuleWorkerTest.php
+++ b/lib/tests/phpunit/SitesModuleWorkerTest.php
@@ -102,21 +102,25 @@
}
/**
- * @dataProvider getModifiedHashProvider
+ * @dataProvider getDefinitionSummaryProvider
*/
- public function testGetModifiedHash( array $workerLists ) {
+ public function testGetDefinitionSummary( array $workerLists ) {
$results = array();
+
+ // Verify the dataHash
/** @var SitesModuleWorker[] $workers */
foreach ( $workerLists as $name => $workers ) {
foreach ( $workers as $worker ) {
- $value = $worker->getModifiedHash();
+ $summary = $worker->getDefinitionSummary();
+ $this->assertCount( 1, $summary );
+ $hash = $summary['dataHash'];
if ( isset( $results[ $name ] ) ) {
$this->assertEquals(
- $results[ $name ], $value,
'getModifiedHash should return the same value for equivalent settings'
+ $results[ $name ], $hash,
'getDefinitionSummary should return the same data hash for equivalent settings'
);
} else {
- $results[ $name ] = $value;
+ $results[ $name ] = $hash;
}
}
}
@@ -125,7 +129,7 @@
$this->assertEmpty( $collidingValues, 'Different settings lead
to same hash' );
}
- public function getModifiedHashProvider() {
+ public function getDefinitionSummaryProvider() {
$site = new MediaWikiSite();
$site->setGlobalId( 'siteid' );
$site->setGroup( 'allowedgroup' );
@@ -163,20 +167,20 @@
);
}
- public function testGetModifiedHash_caching() {
+ public function testGetDefinitionSummary_caching() {
$cacheKey = wfMemcKey( 'wikibase-sites-module-modified-hash' );
$cache = new HashBagOStuff();
$worker = $this->newSitesModuleWorker( array(), array( 'foo' ),
array(), $cache );
// Make sure whatever hash is computed ends up in the cache
- $hash = $worker->getModifiedHash();
- $this->assertSame( $hash, $cache->get( $cacheKey ) );
+ $summary = $worker->getDefinitionSummary();
+ $this->assertSame( $summary['dataHash'], $cache->get( $cacheKey
) );
$cache->set( $cacheKey, 'cache all the things!' );
// Verify that cached results are returned
- $hash = $worker->getModifiedHash();
- $this->assertSame( 'cache all the things!', $hash );
+ $summary = $worker->getDefinitionSummary();
+ $this->assertSame( 'cache all the things!',
$summary['dataHash'] );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/258772
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id1466a2a780c0553b663bf52848ad4ff985fc66f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits