diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- 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, c 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