[MediaWiki-commits] [Gerrit] mediawiki/core[master]: resourceloader: Include lessVars in FileModule definition su...

2017-07-27 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/368122 )

Change subject: resourceloader: Include lessVars in FileModule definition 
summary
..


resourceloader: Include lessVars in FileModule definition summary

This already worked as expected for any module that uses the new
enableModuleContentVersion model, but for the majority of file modules
this is not yet the case for performance reasons. As such, make
sure lessVars are included in our manual tracking.

Include it conditionally to avoid changing the array for other modules,
which would needlessly invalidate their cache.

Bug: T171809
Change-Id: Ib250068e0ecfc29a09ca33c23bef901ee0482bf2
---
M includes/resourceloader/ResourceLoaderFileModule.php
M tests/common/TestsAutoLoader.php
M tests/phpunit/ResourceLoaderTestCase.php
M tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
4 files changed, 42 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/includes/resourceloader/ResourceLoaderFileModule.php 
b/includes/resourceloader/ResourceLoaderFileModule.php
index 79b8e79..4675191 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -580,6 +580,12 @@
'fileHashes' => $this->getFileHashes( $context ),
'messageBlob' => $this->getMessageBlob( $context ),
];
+
+   $lessVars = $this->getLessVars( $context );
+   if ( $lessVars ) {
+   $summary[] = [ 'lessVars' => $lessVars ];
+   }
+
return $summary;
}
 
diff --git a/tests/common/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php
index 3de3ba7..9b9ea6d 100644
--- a/tests/common/TestsAutoLoader.php
+++ b/tests/common/TestsAutoLoader.php
@@ -56,6 +56,7 @@
'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php",
'ResourceLoaderTestCase' => 
"$testDir/phpunit/ResourceLoaderTestCase.php",
'ResourceLoaderTestModule' => 
"$testDir/phpunit/ResourceLoaderTestCase.php",
+   'ResourceLoaderFileTestModule' => 
"$testDir/phpunit/ResourceLoaderTestCase.php",
'ResourceLoaderFileModuleTestModule' => 
"$testDir/phpunit/ResourceLoaderTestCase.php",
'EmptyResourceLoader' => "$testDir/phpunit/ResourceLoaderTestCase.php",
'TestUser' => "$testDir/phpunit/includes/TestUser.php",
diff --git a/tests/phpunit/ResourceLoaderTestCase.php 
b/tests/phpunit/ResourceLoaderTestCase.php
index d8f89fb..f75cc22 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -153,6 +153,22 @@
}
 }
 
+class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
+   protected $lessVars = [];
+
+   public function __construct( $options = [], $test = [] ) {
+   parent::__construct( $options );
+
+   foreach ( $test as $key => $value ) {
+   $this->$key = $value;
+   }
+   }
+
+   public function getLessVars( ResourceLoaderContext $context ) {
+   return $this->lessVars;
+   }
+}
+
 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
 }
 
diff --git 
a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
index ded56e9..e82bab7 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
@@ -331,4 +331,23 @@
'Leading BOM removed when concatenating files'
);
}
+
+   /**
+* @covers ResourceLoaderFileModule::getDefinitionSummary
+*/
+   public function testGetVersionHash() {
+   $context = $this->getResourceLoaderContext();
+
+   // Less variables
+   $module = new ResourceLoaderFileTestModule();
+   $version = $module->getVersionHash( $context );
+   $module = new ResourceLoaderFileTestModule( [], [
+   'lessVars' => [ 'key' => 'value' ],
+   ] );
+   $this->assertNotEquals(
+   $version,
+   $module->getVersionHash( $context ),
+   'Using less variables is significant'
+   );
+   }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib250068e0ecfc29a09ca33c23bef901ee0482bf2
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle 
Gerrit-Reviewer: Jdlrobson 
Gerrit-Reviewer: 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: resourceloader: Include lessVars in FileModule definition su...

2017-07-26 Thread Krinkle (Code Review)
Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368122 )

Change subject: resourceloader: Include lessVars in FileModule definition 
summary
..

resourceloader: Include lessVars in FileModule definition summary

This already worked as expected for any module that uses the new
enableModuleContentVersion model, but for the majority of file modules
this is not yet the case for performance reasons. As such, make
sure lessVars are included in our manual tracking.

Include it conditionally to avoid changing the array for other modules,
which would needlessly invalidate their cache.

Bug: T171809
Change-Id: Ib250068e0ecfc29a09ca33c23bef901ee0482bf2
---
M includes/resourceloader/ResourceLoaderFileModule.php
M tests/phpunit/ResourceLoaderTestCase.php
M tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
3 files changed, 41 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/22/368122/1

diff --git a/includes/resourceloader/ResourceLoaderFileModule.php 
b/includes/resourceloader/ResourceLoaderFileModule.php
index 79b8e79..4675191 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -580,6 +580,12 @@
'fileHashes' => $this->getFileHashes( $context ),
'messageBlob' => $this->getMessageBlob( $context ),
];
+
+   $lessVars = $this->getLessVars( $context );
+   if ( $lessVars ) {
+   $summary[] = [ 'lessVars' => $lessVars ];
+   }
+
return $summary;
}
 
diff --git a/tests/phpunit/ResourceLoaderTestCase.php 
b/tests/phpunit/ResourceLoaderTestCase.php
index d8f89fb..f75cc22 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -153,6 +153,22 @@
}
 }
 
+class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
+   protected $lessVars = [];
+
+   public function __construct( $options = [], $test = [] ) {
+   parent::__construct( $options );
+
+   foreach ( $test as $key => $value ) {
+   $this->$key = $value;
+   }
+   }
+
+   public function getLessVars( ResourceLoaderContext $context ) {
+   return $this->lessVars;
+   }
+}
+
 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
 }
 
diff --git 
a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
index ded56e9..e82bab7 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
@@ -331,4 +331,23 @@
'Leading BOM removed when concatenating files'
);
}
+
+   /**
+* @covers ResourceLoaderFileModule::getDefinitionSummary
+*/
+   public function testGetVersionHash() {
+   $context = $this->getResourceLoaderContext();
+
+   // Less variables
+   $module = new ResourceLoaderFileTestModule();
+   $version = $module->getVersionHash( $context );
+   $module = new ResourceLoaderFileTestModule( [], [
+   'lessVars' => [ 'key' => 'value' ],
+   ] );
+   $this->assertNotEquals(
+   $version,
+   $module->getVersionHash( $context ),
+   'Using less variables is significant'
+   );
+   }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib250068e0ecfc29a09ca33c23bef901ee0482bf2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle 

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