resourceloader: Add filter cache version to module version hash
authorRoan Kattouw <roan.kattouw@gmail.com>
Fri, 29 Sep 2017 20:35:00 +0000 (13:35 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 24 Sep 2018 17:10:48 +0000 (17:10 +0000)
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
includes/resourceloader/ResourceLoaderModule.php
tests/phpunit/includes/OutputPageTest.php

index 604a140..5621dcd 100644 (file)
@@ -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 );
index 79ad0ee..30b2aa7 100644 (file)
@@ -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,
                ];
        }
 
index 5a2d1f7..d334b73 100644 (file)
@@ -1800,7 +1800,7 @@ class OutputPageTest extends MediaWikiTestCase {
                                'exemptStyleModules' => [ 'site' => [ 'site.styles' ], 'user' => [ 'user.styles' ] ],
                                '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
                                '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=0nrehaq"/>',
+                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
                        ],
                        'custom modules' => [
                                'exemptStyleModules' => [
@@ -1811,7 +1811,7 @@ class OutputPageTest extends MediaWikiTestCase {
                                '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.site.a%2Cb&amp;only=styles&amp;skin=fallback"/>' . "\n" .
                                '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
                                '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.user&amp;only=styles&amp;skin=fallback&amp;version=0a56zyi"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=0nrehaq"/>',
+                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
                        ],
                ];
                // phpcs:enable