mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.8.x] Fixed #24242 -- Improved efficiency of utils.text.compress_sequence()
The function no longer flushes zfile after each write as doing so can
lead to the gzipped streamed content being larger than the original
content; each flush adds a 5/6 byte type 0 block. Removing this means
buf.read() may return nothing, so only yield if that has some data.
Testing shows without the flush() the buffer is being flushed every 17k
or so and compresses the same as if it had been done as a whole string.
Backport of caa3562d5b from master
This commit is contained in:
committed by
Tim Graham
parent
d585ade0df
commit
2a55301f9f
@@ -304,6 +304,8 @@ class StreamingBuffer(object):
|
||||
self.vals.append(val)
|
||||
|
||||
def read(self):
|
||||
if not self.vals:
|
||||
return b''
|
||||
ret = b''.join(self.vals)
|
||||
self.vals = []
|
||||
return ret
|
||||
@@ -323,8 +325,9 @@ def compress_sequence(sequence):
|
||||
yield buf.read()
|
||||
for item in sequence:
|
||||
zfile.write(item)
|
||||
zfile.flush()
|
||||
yield buf.read()
|
||||
data = buf.read()
|
||||
if data:
|
||||
yield data
|
||||
zfile.close()
|
||||
yield buf.read()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user