##// 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 1160 def cache_diff(cached_diff_file, diff, commits):
1161 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1161 1162
1162 1163 struct = {
1163 1164 'version': CURRENT_DIFF_VERSION,
@@ -1165,16 +1166,23 b' def cache_diff(cached_diff_file, diff, c'
1165 1166 'commits': commits
1166 1167 }
1167 1168
1169 start = time.time()
1168 1170 try:
1169 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1170 pickle.dump(struct, f)
1171 log.debug('Saved diff cache under %s', cached_diff_file)
1171 if mode == 'plain':
1172 with open(cached_diff_file, 'wb') as f:
1173 pickle.dump(struct, f)
1174 else:
1175 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1176 pickle.dump(struct, f)
1172 1177 except Exception:
1173 1178 log.warn('Failed to save cache', exc_info=True)
1174 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 1184 def load_cached_diff(cached_diff_file):
1185 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1178 1186
1179 1187 default_struct = {
1180 1188 'version': CURRENT_DIFF_VERSION,
@@ -1184,15 +1192,19 b' def load_cached_diff(cached_diff_file):'
1184 1192
1185 1193 has_cache = os.path.isfile(cached_diff_file)
1186 1194 if not has_cache:
1195 log.debug('Reading diff cache file failed', cached_diff_file)
1187 1196 return default_struct
1188 1197
1189 1198 data = None
1199
1190 1200 start = time.time()
1191 1201 try:
1192 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1193 data = pickle.load(f)
1194 load_time = time.time() - start
1195 log.debug('Loaded diff cache from %s in %.3fs', cached_diff_file, load_time)
1202 if mode == 'plain':
1203 with open(cached_diff_file, 'rb') as f:
1204 data = pickle.load(f)
1205 else:
1206 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1207 data = pickle.load(f)
1196 1208 except Exception:
1197 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 1221 _cleanup_cache_file(cached_diff_file)
1210 1222 return default_struct
1211 1223
1224 log.debug('Loaded diff cache from %s in %.3fs', cached_diff_file, time.time() - start)
1225
1212 1226 return data
1213 1227
1214 1228
General Comments 0
You need to be logged in to leave comments. Login now