Hoo man has uploaded a new change for review.

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

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, 28 insertions(+), 30 deletions(-)


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

diff --git a/lib/includes/modules/SitesModule.php 
b/lib/includes/modules/SitesModule.php
index 7ae14fa..ff0d71b 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
         */
-       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 ) {
+               // Appending arrays using + is the right thing to do here: All 
keys
+               // are named and we want the first one to overwrite the second 
one.
+               return $this->worker->getDefinitionSummary() + 
parent::getDefinitionSummary( $context );
        }
 
 }
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..60fde3e 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();
+                               $sumamry = $worker->getDefinitionSummary();
+                               $this->assertCount( 1, $sumamry );
+                               $hash = $sumamry['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: newchange
Gerrit-Change-Id: Id1466a2a780c0553b663bf52848ad4ff985fc66f
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

Reply via email to