From 1ed0a109ec00c3230da17713d438e1f5d275f7d1 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 29 Sep 2017 13:35:00 -0700 Subject: [PATCH] resourceloader: Add filter cache version to module version hash We already had a $filterCacheVersion variable, but it was only used for the internal cache for JS and CSS minification, which is not enough. If there is a breaking change in either of these processes, we also need to invalidate version hashes. This commit renames ResourceLoader::$filterCacheVersion to ResourceLoader::CACHE_VERSION and takes it into account in getVersionHash(). Adding it to getDefinitionSummary() is not sufficient, because content-hashed modules also need to be invalidated when there's a breaking change in the minifiers. This cache version can also be incremented when there's a breaking change in image embedding or LESS compilation, although content hashing deals with that already, so we could also add a separate cache version for those that's only added to getDefinitionSummary(). Bug: T176884 Change-Id: Ife6efa71f310c90b9951afa02212b2cb6766e76d --- includes/resourceloader/ResourceLoader.php | 5 +++-- includes/resourceloader/ResourceLoaderModule.php | 3 +++ tests/phpunit/includes/OutputPageTest.php | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 604a140de5..5621dcda97 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -37,7 +37,7 @@ use Wikimedia\WrappedString; */ class ResourceLoader implements LoggerAwareInterface { /** @var int */ - protected static $filterCacheVersion = 8; + const CACHE_VERSION = 8; /** @var bool */ protected static $debugMode = null; @@ -199,7 +199,8 @@ class ResourceLoader implements LoggerAwareInterface { 'resourceloader', 'filter', $filter, - self::$filterCacheVersion, md5( $data ) + self::CACHE_VERSION, + md5( $data ) ); $result = $cache->get( $key ); diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 79ad0eef60..30b2aa7949 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -883,6 +883,9 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { public function getDefinitionSummary( ResourceLoaderContext $context ) { return [ '_class' => static::class, + // Make sure that when filter cache for minification is invalidated, + // we also change the HTTP urls and mw.loader.store keys (T176884). + '_cacheVersion' => ResourceLoader::CACHE_VERSION, ]; } diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 5a2d1f7f02..d334b73925 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -1800,7 +1800,7 @@ class OutputPageTest extends MediaWikiTestCase { 'exemptStyleModules' => [ 'site' => [ 'site.styles' ], 'user' => [ 'user.styles' ] ], '' . "\n" . '' . "\n" . - '', + '', ], 'custom modules' => [ 'exemptStyleModules' => [ @@ -1811,7 +1811,7 @@ class OutputPageTest extends MediaWikiTestCase { '' . "\n" . '' . "\n" . '' . "\n" . - '', + '', ], ]; // phpcs:enable -- 2.20.1