From fe2adc121d642c9e31ac4eaa06ca81e87abc2329 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 4 Nov 2022 09:59:57 -0500 Subject: [PATCH 1/2] PYTHON-3502 GridFSBucket.download_to_stream slow --- gridfs/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gridfs/__init__.py b/gridfs/__init__.py index 6ab843a85e..692567b2de 100644 --- a/gridfs/__init__.py +++ b/gridfs/__init__.py @@ -796,7 +796,10 @@ def download_to_stream( Added ``session`` parameter. """ with self.open_download_stream(file_id, session=session) as gout: - for chunk in gout: + while True: + chunk = gout.readchunk() + if not len(chunk): + break destination.write(chunk) @_csot.apply @@ -977,7 +980,10 @@ def download_to_stream_by_name( Added ``session`` parameter. """ with self.open_download_stream_by_name(filename, revision, session=session) as gout: - for chunk in gout: + while True: + chunk = gout.readchunk() + if not len(chunk): + break destination.write(chunk) def rename( From dda9a02fcc44d5eb7dff6f44a62628105d976888 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 4 Nov 2022 13:02:48 -0500 Subject: [PATCH 2/2] add changelog entry --- doc/changelog.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/changelog.rst b/doc/changelog.rst index 4688a8fb65..4f4e5ace71 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Changes in Version 4.3.3 +------------------------ + +- Fixed a performance regression in :meth:`~gridfs.GridOut.download_to_stream` + and :meth:`~gridfs.GridOut.download_to_stream_by_name` by reading in chunks + instead of line by line. + + Changes in Version 4.3 (4.3.2) ------------------------------