PYTHON-3502 GridFSBucket.download_to_stream slow (#1108)

This commit is contained in:
Steven Silvester 2022-11-04 13:47:32 -05:00 committed by GitHub
parent 04356b0ffd
commit a00aabfa0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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)
------------------------------

View File

@ -796,7 +796,10 @@ class GridFSBucket(object):
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 @@ class GridFSBucket(object):
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(