Skip to content

Commit

Permalink
Minor perf improvement and fixed unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
andresriancho committed Apr 24, 2019
1 parent 21437e5 commit 717d42e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions w3af/core/data/db/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ def _queue_compression_requests(self, response_id):
#
session_dir = self._session_dir

files = [os.path.join(session_dir, f) for f in os.listdir(session_dir)]
files = [f for f in files if f.endswith(self._EXTENSION)]
files = [f for f in os.listdir(session_dir) if f.endswith(self._EXTENSION)]
files = [os.path.join(session_dir, f) for f in files]

if len(files) <= HistoryItem._MIN_FILE_COUNT:
return
Expand All @@ -525,6 +525,7 @@ def _queue_compression_requests(self, response_id):
#
files.sort(key=lambda trace_file: get_trace_id(trace_file))
files = files[:-self._UNCOMPRESSED_FILES]

#
# Compress in 150 file batches, and making sure that the filenames
# are numerically ordered. We need this order to have 1, 2, ... 150 in
Expand Down
8 changes: 4 additions & 4 deletions w3af/core/data/db/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ def test_save_load(self):

def test_save_load_compressed(self):
force_compression_count = HistoryItem._UNCOMPRESSED_FILES + HistoryItem._COMPRESSED_FILE_BATCH
force_compression_count += 10
force_compression_count += 150

url = URL('http://w3af.com/a/b/c.php')
headers = Headers([('Content-Type', 'text/html')])
body = '<html>' + LOREM * 20

for i in xrange(force_compression_count):
for i in xrange(1, force_compression_count):
request = HTTPRequest(url, data='a=%s' % i)

response = HTTPResponse(200, body, headers, url, url)
Expand All @@ -155,10 +155,10 @@ def test_save_load_compressed(self):
h.response = response
h.save()

compressed_file = os.path.join(h.get_session_dir(), '0-149.zip')
compressed_file = os.path.join(h.get_session_dir(), '1-150.zip')
self.assertTrue(os.path.exists(compressed_file))

expected_files = ['%s.trace' % i for i in range(HistoryItem._COMPRESSED_FILE_BATCH)]
expected_files = ['%s.trace' % i for i in range(1, HistoryItem._COMPRESSED_FILE_BATCH + 1)]

_zip = zipfile.ZipFile(compressed_file, mode='r')
self.assertEqual(_zip.namelist(), expected_files)
Expand Down

0 comments on commit 717d42e

Please sign in to comment.