Fix #1077: improved performance and error handling in fetch_attachment

This commit is contained in:
Agate 2020-04-21 14:47:16 +02:00
parent 08ffc7adc5
commit c529d4d260
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
2 changed files with 10 additions and 2 deletions

View file

@ -77,7 +77,7 @@ def fetch_remote_attachment(attachment, filename=None, save=True):
attachment.last_fetch_date = timezone.now()
with tempfile.TemporaryFile() as tf:
with s.get(attachment.url, timeout=5, stream=True) as r:
for chunk in r.iter_content():
for chunk in r.iter_content(chunk_size=1024 * 100):
tf.write(chunk)
tf.seek(0)
if not filename: