From b4ef64817c0af7bf73e6828ce9ccaeb301394c04 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Mon, 24 Sep 2018 15:59:38 +0200 Subject: [PATCH] diffs: make validation of version, so we can change diffs and force re-cache if diffs are in old version. --- rhodecode/lib/diffs.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py index 189a13be..4ac51356 100644 --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -1134,10 +1134,23 @@ class DiffLimitExceeded(Exception): pass +# NOTE(marcink): if diffs.mako change, probably this +# needs a bump to next version +CURRENT_DIFF_VERSION = 'v1' + + +def _cleanup_cache_file(cached_diff_file): + # cleanup file to not store it "damaged" + try: + os.remove(cached_diff_file) + except Exception: + log.exception('Failed to cleanup path %s', cached_diff_file) + + def cache_diff(cached_diff_file, diff, commits): struct = { - 'version': 'v1', + 'version': CURRENT_DIFF_VERSION, 'diff': diff, 'commits': commits } @@ -1148,17 +1161,13 @@ def cache_diff(cached_diff_file, diff, commits): log.debug('Saved diff cache under %s', cached_diff_file) except Exception: log.warn('Failed to save cache', exc_info=True) - # cleanup file to not store it "damaged" - try: - os.remove(cached_diff_file) - except Exception: - log.exception('Failed to cleanup path %s', cached_diff_file) + _cleanup_cache_file(cached_diff_file) def load_cached_diff(cached_diff_file): default_struct = { - 'version': 'v1', + 'version': CURRENT_DIFF_VERSION, 'diff': None, 'commits': None } @@ -1182,6 +1191,12 @@ def load_cached_diff(cached_diff_file): # old version of data ? data = default_struct + # check version + if data.get('version') != CURRENT_DIFF_VERSION: + # purge cache + _cleanup_cache_file(cached_diff_file) + return default_struct + return data