##// END OF EJS Templates
dffs-cache: allow plain mode without bz2 for even better performance but more disk space.
marcink -
r3839:3efd6845 default
parent child Browse files
Show More
@@ -1158,6 +1158,7 b' def _cleanup_cache_file(cached_diff_file'
1158
1158
1159
1159
1160 def cache_diff(cached_diff_file, diff, commits):
1160 def cache_diff(cached_diff_file, diff, commits):
1161 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1161
1162
1162 struct = {
1163 struct = {
1163 'version': CURRENT_DIFF_VERSION,
1164 'version': CURRENT_DIFF_VERSION,
@@ -1165,16 +1166,23 b' def cache_diff(cached_diff_file, diff, c'
1165 'commits': commits
1166 'commits': commits
1166 }
1167 }
1167
1168
1169 start = time.time()
1168 try:
1170 try:
1169 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1171 if mode == 'plain':
1170 pickle.dump(struct, f)
1172 with open(cached_diff_file, 'wb') as f:
1171 log.debug('Saved diff cache under %s', cached_diff_file)
1173 pickle.dump(struct, f)
1174 else:
1175 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1176 pickle.dump(struct, f)
1172 except Exception:
1177 except Exception:
1173 log.warn('Failed to save cache', exc_info=True)
1178 log.warn('Failed to save cache', exc_info=True)
1174 _cleanup_cache_file(cached_diff_file)
1179 _cleanup_cache_file(cached_diff_file)
1175
1180
1181 log.debug('Saved diff cache under %s in %.3fs', cached_diff_file, time.time() - start)
1182
1176
1183
1177 def load_cached_diff(cached_diff_file):
1184 def load_cached_diff(cached_diff_file):
1185 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1178
1186
1179 default_struct = {
1187 default_struct = {
1180 'version': CURRENT_DIFF_VERSION,
1188 'version': CURRENT_DIFF_VERSION,
@@ -1184,15 +1192,19 b' def load_cached_diff(cached_diff_file):'
1184
1192
1185 has_cache = os.path.isfile(cached_diff_file)
1193 has_cache = os.path.isfile(cached_diff_file)
1186 if not has_cache:
1194 if not has_cache:
1195 log.debug('Reading diff cache file failed', cached_diff_file)
1187 return default_struct
1196 return default_struct
1188
1197
1189 data = None
1198 data = None
1199
1190 start = time.time()
1200 start = time.time()
1191 try:
1201 try:
1192 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1202 if mode == 'plain':
1193 data = pickle.load(f)
1203 with open(cached_diff_file, 'rb') as f:
1194 load_time = time.time() - start
1204 data = pickle.load(f)
1195 log.debug('Loaded diff cache from %s in %.3fs', cached_diff_file, load_time)
1205 else:
1206 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1207 data = pickle.load(f)
1196 except Exception:
1208 except Exception:
1197 log.warn('Failed to read diff cache file', exc_info=True)
1209 log.warn('Failed to read diff cache file', exc_info=True)
1198
1210
@@ -1209,6 +1221,8 b' def load_cached_diff(cached_diff_file):'
1209 _cleanup_cache_file(cached_diff_file)
1221 _cleanup_cache_file(cached_diff_file)
1210 return default_struct
1222 return default_struct
1211
1223
1224 log.debug('Loaded diff cache from %s in %.3fs', cached_diff_file, time.time() - start)
1225
1212 return data
1226 return data
1213
1227
1214
1228
General Comments 0
You need to be logged in to leave comments. Login now