##// END OF EJS Templates
diffs: switched bz2 into gzip since it can be 10x faster in some cases with only slight size penalty
marcink -
r3854:7b87073e default
parent child Browse files
Show More
@@ -26,6 +26,7 b' Set of diffing helpers, previously part '
26 import os
26 import os
27 import re
27 import re
28 import bz2
28 import bz2
29 import gzip
29 import time
30 import time
30
31
31 import collections
32 import collections
@@ -1157,8 +1158,17 b' def _cleanup_cache_file(cached_diff_file'
1157 log.exception('Failed to cleanup path %s', cached_diff_file)
1158 log.exception('Failed to cleanup path %s', cached_diff_file)
1158
1159
1159
1160
1161 def _get_compression_mode(cached_diff_file):
1162 mode = 'bz2'
1163 if 'mode:plain' in cached_diff_file:
1164 mode = 'plain'
1165 elif 'mode:gzip' in cached_diff_file:
1166 mode = 'gzip'
1167 return mode
1168
1169
1160 def cache_diff(cached_diff_file, diff, commits):
1170 def cache_diff(cached_diff_file, diff, commits):
1161 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1171 compression_mode = _get_compression_mode(cached_diff_file)
1162
1172
1163 struct = {
1173 struct = {
1164 'version': CURRENT_DIFF_VERSION,
1174 'version': CURRENT_DIFF_VERSION,
@@ -1168,9 +1178,12 b' def cache_diff(cached_diff_file, diff, c'
1168
1178
1169 start = time.time()
1179 start = time.time()
1170 try:
1180 try:
1171 if mode == 'plain':
1181 if compression_mode == 'plain':
1172 with open(cached_diff_file, 'wb') as f:
1182 with open(cached_diff_file, 'wb') as f:
1173 pickle.dump(struct, f)
1183 pickle.dump(struct, f)
1184 elif compression_mode == 'gzip':
1185 with gzip.GzipFile(cached_diff_file, 'wb') as f:
1186 pickle.dump(struct, f)
1174 else:
1187 else:
1175 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1188 with bz2.BZ2File(cached_diff_file, 'wb') as f:
1176 pickle.dump(struct, f)
1189 pickle.dump(struct, f)
@@ -1182,7 +1195,7 b' def cache_diff(cached_diff_file, diff, c'
1182
1195
1183
1196
1184 def load_cached_diff(cached_diff_file):
1197 def load_cached_diff(cached_diff_file):
1185 mode = 'plain' if 'mode:plain' in cached_diff_file else ''
1198 compression_mode = _get_compression_mode(cached_diff_file)
1186
1199
1187 default_struct = {
1200 default_struct = {
1188 'version': CURRENT_DIFF_VERSION,
1201 'version': CURRENT_DIFF_VERSION,
@@ -1199,9 +1212,12 b' def load_cached_diff(cached_diff_file):'
1199
1212
1200 start = time.time()
1213 start = time.time()
1201 try:
1214 try:
1202 if mode == 'plain':
1215 if compression_mode == 'plain':
1203 with open(cached_diff_file, 'rb') as f:
1216 with open(cached_diff_file, 'rb') as f:
1204 data = pickle.load(f)
1217 data = pickle.load(f)
1218 elif compression_mode == 'gzip':
1219 with gzip.GzipFile(cached_diff_file, 'rb') as f:
1220 data = pickle.load(f)
1205 else:
1221 else:
1206 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1222 with bz2.BZ2File(cached_diff_file, 'rb') as f:
1207 data = pickle.load(f)
1223 data = pickle.load(f)
@@ -1245,6 +1261,7 b' def diff_cache_exist(cache_storage, *arg'
1245 """
1261 """
1246 Based on all generated arguments check and return a cache path
1262 Based on all generated arguments check and return a cache path
1247 """
1263 """
1264 args = list(args) + ['mode:gzip']
1248 cache_key = generate_diff_cache_key(*args)
1265 cache_key = generate_diff_cache_key(*args)
1249 cache_file_path = os.path.join(cache_storage, cache_key)
1266 cache_file_path = os.path.join(cache_storage, cache_key)
1250 # prevent path traversal attacks using some param that have e.g '../../'
1267 # prevent path traversal attacks using some param that have e.g '../../'
General Comments 0
You need to be logged in to leave comments. Login now