##// END OF EJS Templates
diffs: make validation of version, so we can change diffs and force re-cache if diffs are in old version.
marcink -
r3079:b924aea3 default
parent child Browse files
Show More
@@ -1134,10 +1134,23 b' class DiffLimitExceeded(Exception):'
1134 pass
1134 pass
1135
1135
1136
1136
1137 # NOTE(marcink): if diffs.mako change, probably this
1138 # needs a bump to next version
1139 CURRENT_DIFF_VERSION = 'v1'
1140
1141
1142 def _cleanup_cache_file(cached_diff_file):
1143 # cleanup file to not store it "damaged"
1144 try:
1145 os.remove(cached_diff_file)
1146 except Exception:
1147 log.exception('Failed to cleanup path %s', cached_diff_file)
1148
1149
1137 def cache_diff(cached_diff_file, diff, commits):
1150 def cache_diff(cached_diff_file, diff, commits):
1138
1151
1139 struct = {
1152 struct = {
1140 'version': 'v1',
1153 'version': CURRENT_DIFF_VERSION,
1141 'diff': diff,
1154 'diff': diff,
1142 'commits': commits
1155 'commits': commits
1143 }
1156 }
@@ -1148,17 +1161,13 b' def cache_diff(cached_diff_file, diff, c'
1148 log.debug('Saved diff cache under %s', cached_diff_file)
1161 log.debug('Saved diff cache under %s', cached_diff_file)
1149 except Exception:
1162 except Exception:
1150 log.warn('Failed to save cache', exc_info=True)
1163 log.warn('Failed to save cache', exc_info=True)
1151 # cleanup file to not store it "damaged"
1164 _cleanup_cache_file(cached_diff_file)
1152 try:
1153 os.remove(cached_diff_file)
1154 except Exception:
1155 log.exception('Failed to cleanup path %s', cached_diff_file)
1156
1165
1157
1166
1158 def load_cached_diff(cached_diff_file):
1167 def load_cached_diff(cached_diff_file):
1159
1168
1160 default_struct = {
1169 default_struct = {
1161 'version': 'v1',
1170 'version': CURRENT_DIFF_VERSION,
1162 'diff': None,
1171 'diff': None,
1163 'commits': None
1172 'commits': None
1164 }
1173 }
@@ -1182,6 +1191,12 b' def load_cached_diff(cached_diff_file):'
1182 # old version of data ?
1191 # old version of data ?
1183 data = default_struct
1192 data = default_struct
1184
1193
1194 # check version
1195 if data.get('version') != CURRENT_DIFF_VERSION:
1196 # purge cache
1197 _cleanup_cache_file(cached_diff_file)
1198 return default_struct
1199
1185 return data
1200 return data
1186
1201
1187
1202
General Comments 0
You need to be logged in to leave comments. Login now