From: Timo Tijhof Date: Wed, 17 Aug 2016 18:57:57 +0000 (-0700) Subject: ResourceLoaderImage: Use hashes for versioning instead of timestamps X-Git-Tag: 1.31.0-rc.0~5997 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=453ada4be7b70332e2e0d296302ec8afa3230c86;p=lhc%2Fweb%2Fwiklou.git ResourceLoaderImage: Use hashes for versioning instead of timestamps Remove use of the deprecated getModifiedTime() method and incorporate file information in getDefinitionSummary() directly, instead of relying on the parent class to include getModifiedTime(). Change getDefinitionSummary() to append to the summary instead of setting arbitrary keys in the array directly to avoid conflicts. This matches the pattern used elsewhere. Change ResourceLoaderImage to use file hashes instead of timestamps to avoid needless cache invalidation. At Wikimedia these modules tend to roll over every week due to git not storing timestamps. See also T104950, 9112c9347b, f37cee996. Change-Id: I5d019bfb991c3b8042d1db14a853ba46cc690315 --- diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php index 6cdab1bbfc..43327c91cc 100644 --- a/includes/resourceloader/ResourceLoaderImageModule.php +++ b/includes/resourceloader/ResourceLoaderImageModule.php @@ -393,6 +393,8 @@ class ResourceLoaderImageModule extends ResourceLoaderModule { public function getDefinitionSummary( ResourceLoaderContext $context ) { $this->loadFromDefinition(); $summary = parent::getDefinitionSummary( $context ); + + $options = []; foreach ( [ 'localBasePath', 'images', @@ -401,29 +403,27 @@ class ResourceLoaderImageModule extends ResourceLoaderModule { 'selectorWithoutVariant', 'selectorWithVariant', ] as $member ) { - $summary[$member] = $this->{$member}; + $options[$member] = $this->{$member}; }; + + $summary[] = [ + 'options' => $options, + 'fileHashes' => $this->getFileHashes( $context ), + ]; return $summary; } /** - * Get the last modified timestamp of this module. - * - * @param ResourceLoaderContext $context Context in which to calculate - * the modified time - * @return int UNIX timestamp + * Helper method for getDefinitionSummary. */ - public function getModifiedTime( ResourceLoaderContext $context ) { + protected function getFileHashes( ResourceLoaderContext $context ) { $this->loadFromDefinition(); $files = []; foreach ( $this->getImages( $context ) as $name => $image ) { $files[] = $image->getPath( $context ); } - $files = array_values( array_unique( $files ) ); - $filesMtime = max( array_map( [ __CLASS__, 'safeFilemtime' ], $files ) ); - - return $filesMtime; + return array_map( [ __CLASS__, 'safeFileHash' ], $files ); } /**