From: Timo Tijhof Date: Tue, 31 Mar 2015 18:17:11 +0000 (+0100) Subject: resourceloader: Simplify getHashMtime() to merely a timestamp X-Git-Tag: 1.31.0-rc.0~11912 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=885a1e0703984cc9d4665b168b0097e20f2dc695;p=lhc%2Fweb%2Fwiklou.git resourceloader: Simplify getHashMtime() to merely a timestamp Similar to what getDefinitionMtime() does already. No need to repeat the hash. No need for an array that needs serialising and unserialising internally. Change the hash key to avoid using old cache values. Also moved the comment about hashes being included in the key to this method. getDefinitionMtime() is a later method that performs the same logic but doesn't need the entire story again. Follows-up 044713c4, d3bdda32. Change-Id: Idd83de5ac27138a2dbf2ec49d81ea9188bd6ad57 --- diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 572428e6bb..ed16521be8 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -458,21 +458,26 @@ abstract class ResourceLoaderModule { return 1; } + // Embed the hash itself in the cache key. This allows for a few nifty things: + // - During deployment, servers with old and new versions of the code communicating + // with the same memcached will not override the same key repeatedly increasing + // the timestamp. + // - In case of the definition changing and then changing back in a short period of time + // (e.g. in case of a revert or a corrupt server) the old timestamp and client-side cache + // url will be re-used. + // - If different context-combinations (e.g. same skin, same language or some combination + // thereof) result in the same definition, they will use the same hash and timestamp. $cache = wfGetCache( CACHE_ANYTHING ); - $key = wfMemcKey( 'resourceloader', 'modulemodifiedhash', $this->getName(), $hash ); + $key = wfMemcKey( 'resourceloader', 'hashmtime', $this->getName(), $hash ); $data = $cache->get( $key ); - if ( is_array( $data ) && $data['hash'] === $hash ) { - // Hash is still the same, re-use the timestamp of when we first saw this hash. - return $data['timestamp']; + if ( is_int( $data ) && $data > 0 ) { + // We've seen this hash before, re-use the timestamp of when we first saw it. + return $data; } $timestamp = time(); - $cache->set( $key, array( - 'hash' => $hash, - 'timestamp' => $timestamp, - ) ); - + $cache->set( $key, $timestamp ); return $timestamp; } @@ -504,18 +509,7 @@ abstract class ResourceLoaderModule { } $hash = md5( json_encode( $summary ) ); - $cache = wfGetCache( CACHE_ANYTHING ); - - // Embed the hash itself in the cache key. This allows for a few nifty things: - // - During deployment, servers with old and new versions of the code communicating - // with the same memcached will not override the same key repeatedly increasing - // the timestamp. - // - In case of the definition changing and then changing back in a short period of time - // (e.g. in case of a revert or a corrupt server) the old timestamp and client-side cache - // url will be re-used. - // - If different context-combinations (e.g. same skin, same language or some combination - // thereof) result in the same definition, they will use the same hash and timestamp. $key = wfMemcKey( 'resourceloader', 'moduledefinition', $this->getName(), $hash ); $data = $cache->get( $key ); @@ -529,7 +523,6 @@ abstract class ResourceLoaderModule { $timestamp = time(); $cache->set( $key, $timestamp ); - return $timestamp; }