From 885a1e0703984cc9d4665b168b0097e20f2dc695 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 31 Mar 2015 19:17:11 +0100 Subject: [PATCH] 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 --- .../resourceloader/ResourceLoaderModule.php | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) 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; } -- 2.20.1