From 12bb16da8fbadac34e2de318cc79d7d765f35a96 Mon Sep 17 00:00:00 2001 From: farhan Date: Sat, 13 Dec 2025 23:33:33 +0500 Subject: Fixed #36293 -- Avoided buffering streaming responses in GZipMiddleware. This avoids latency and/or blocking. The example of streaming a CSV file was rewritten to employ batching for greater efficiency in all layers (db, HTTP, etc.). The improved performance from batching should outweigh the drag introduced by an additional byte for each flush. Co-authored-by: huoyinghui --- django/utils/text.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'django') diff --git a/django/utils/text.py b/django/utils/text.py index cfe6ceca9e..d1306f9c6f 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -382,6 +382,7 @@ def compress_sequence(sequence, *, max_random_bytes=None): yield buf.read() for item in sequence: zfile.write(item) + zfile.flush() data = buf.read() if data: yield data @@ -398,6 +399,7 @@ async def acompress_sequence(sequence, *, max_random_bytes=None): yield buf.read() async for item in sequence: zfile.write(item) + zfile.flush() data = buf.read() if data: yield data -- cgit v1.3