From 8cbd6a84317044578033a273ebd1e04e9216b4a3 Mon Sep 17 00:00:00 2001 From: Jonathan Rehm Date: Sat, 19 Aug 2017 09:09:12 -0700 Subject: [PATCH] Do not append query string if file_hash is not found --- cps/cache_buster.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cps/cache_buster.py b/cps/cache_buster.py index 6c390792..2e2b9869 100644 --- a/cps/cache_buster.py +++ b/cps/cache_buster.py @@ -25,12 +25,12 @@ def init_cache_busting(app): # compute version component rooted_filename = os.path.join(dirpath, filename) with open(rooted_filename, 'r') as f: - version = hashlib.md5(f.read()).hexdigest()[:7] + file_hash = hashlib.md5(f.read()).hexdigest()[:7] # save version to tables file_path = rooted_filename.replace(static_folder, "") file_path = file_path.replace("\\", "/") # Convert Windows path to web path - hash_table[file_path] = version + hash_table[file_path] = file_hash app.logger.debug('Finished computing cache-busting values') def bust_filename(filename): @@ -44,8 +44,10 @@ def init_cache_busting(app): """ Make `url_for` produce busted filenames when using the 'static' endpoint. """ - if endpoint == 'static': - values["q"] = bust_filename(values['filename']) + if endpoint == "static": + file_hash = bust_filename(values["filename"]) + if file_hash: + values["q"] = file_hash def debusting_static_view(filename): """ @@ -54,5 +56,5 @@ def init_cache_busting(app): return original_static_view(filename=unbust_filename(filename)) # Replace the default static file view with our debusting view. - original_static_view = app.view_functions['static'] - app.view_functions['static'] = debusting_static_view + original_static_view = app.view_functions["static"] + app.view_functions["static"] = debusting_static_view