From 1538edce7b882d902162dc26d7bbaf51a09deae9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 20 Aug 2014 20:26:46 +0200 Subject: [PATCH] ResourceLoaderFileModule: Do not separately cache .less files MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We used to have a second level of caching for them – when a module's cache was invalidated, individual .less files that comprise it would only be recompiled (with all their @imports) if their mktime changed (or if $wgResourceLoaderLESSVars changed). Given that practice has shown that RL modules including .less files usually just include one file that @imports tons of stuff, and given that RL already is very careful about invalidating caches, I think this is unnecessary at best and harmful at worst. The behavior proved problematic when I tried to implement support for per-module LESS variables, values of which were language-dependent – files would not be recompiled for different languages, and getLessCacheKey() is called several levels deep in code that doesn't have access to the context in which the module is being compiled. Change-Id: I667f063507583e4cd3a669e32398d440f1431f7e --- .../ResourceLoaderFileModule.php | 51 ++----------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 9fdeb91ba0..0c84700ece 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -898,61 +898,20 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { return $this->targets; } - /** - * Generate a cache key for a LESS file. - * - * The cache key varies on the file name and the names and values of global - * LESS variables. - * - * @since 1.22 - * @param string $fileName File name of root LESS file. - * @return string Cache key - */ - protected function getLessCacheKey( $fileName ) { - $vars = json_encode( ResourceLoader::getLessVars( $this->getConfig() ) ); - $hash = md5( $fileName . $vars ); - return wfMemcKey( 'resourceloader', 'less', $hash ); - } - /** * Compile a LESS file into CSS. * - * If invalid, returns replacement CSS source consisting of the compilation - * error message encoded as a comment. To save work, we cache a result object - * which comprises the compiled CSS and the names & mtimes of the files - * that were processed. lessphp compares the cached & current mtimes and - * recompiles as necessary. + * Keeps track of all used files and adds them to localFileRefs. * * @since 1.22 - * @throws Exception If Less encounters a parse error - * @throws MWException If Less compilation returns unexpection result + * @throws Exception If lessc encounters a parse error * @param string $fileName File path of LESS source * @return string CSS source */ protected function compileLessFile( $fileName ) { - $key = $this->getLessCacheKey( $fileName ); - $cache = wfGetCache( CACHE_ANYTHING ); - - // The input to lessc. Either an associative array representing the - // cached results of a previous compilation, or the string file name if - // no cache result exists. - $source = $cache->get( $key ); - if ( !is_array( $source ) || !isset( $source['root'] ) ) { - $source = $fileName; - } - $compiler = ResourceLoader::getLessCompiler( $this->getConfig() ); - $result = null; - - $result = $compiler->cachedCompile( $source ); - - if ( !is_array( $result ) ) { - throw new MWException( 'LESS compiler result has type ' - . gettype( $result ) . '; array expected.' ); - } - - $this->localFileRefs += array_keys( $result['files'] ); - $cache->set( $key, $result ); - return $result['compiled']; + $result = $compiler->compileFile( $fileName ); + $this->localFileRefs += array_keys( $compiler->allParsedFiles() ); + return $result; } } -- 2.20.1