Skip to content

Commit a00aabf

Browse files
authored
PYTHON-3502 GridFSBucket.download_to_stream slow (#1108)
1 parent 04356b0 commit a00aabf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

doc/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
Changes in Version 4.3.3
5+
------------------------
6+
7+
- Fixed a performance regression in :meth:`~gridfs.GridOut.download_to_stream`
8+
and :meth:`~gridfs.GridOut.download_to_stream_by_name` by reading in chunks
9+
instead of line by line.
10+
11+
412
Changes in Version 4.3 (4.3.2)
513
------------------------------
614

gridfs/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,10 @@ def download_to_stream(
796796
Added ``session`` parameter.
797797
"""
798798
with self.open_download_stream(file_id, session=session) as gout:
799-
for chunk in gout:
799+
while True:
800+
chunk = gout.readchunk()
801+
if not len(chunk):
802+
break
800803
destination.write(chunk)
801804

802805
@_csot.apply
@@ -977,7 +980,10 @@ def download_to_stream_by_name(
977980
Added ``session`` parameter.
978981
"""
979982
with self.open_download_stream_by_name(filename, revision, session=session) as gout:
980-
for chunk in gout:
983+
while True:
984+
chunk = gout.readchunk()
985+
if not len(chunk):
986+
break
981987
destination.write(chunk)
982988

983989
def rename(

0 commit comments

Comments
 (0)