mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Use generator in Mailbox.get_mail to limit memory leak
This commit is contained in:
parent
9f8d653ada
commit
31ccd2e4aa
3 changed files with 4 additions and 5 deletions
|
|
@ -408,17 +408,16 @@ class Mailbox(models.Model):
|
|||
new_mail = []
|
||||
connection = self.get_connection()
|
||||
if not connection:
|
||||
return new_mail
|
||||
return
|
||||
for message in connection.get_message(condition):
|
||||
msg = self.process_incoming_message(message)
|
||||
if not msg is None:
|
||||
new_mail.append(msg)
|
||||
yield msg
|
||||
self.last_polling = now()
|
||||
if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields
|
||||
self.save(update_fields=['last_polling'])
|
||||
else:
|
||||
self.save()
|
||||
return new_mail
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class EmailMessageTestCase(TestCase):
|
|||
raise EmailIntegrationTimeout()
|
||||
messages = self.mailbox.get_new_mail(condition)
|
||||
if messages:
|
||||
return messages
|
||||
return list(messages)
|
||||
time.sleep(5)
|
||||
|
||||
def _get_email_as_text(self, name):
|
||||
|
|
|
|||
|
|
@ -32,5 +32,5 @@ class TestMailbox(TestCase):
|
|||
'generic_message.eml',
|
||||
))
|
||||
self.assertEqual(mailbox.last_polling, None)
|
||||
mailbox.get_new_mail()
|
||||
list(mailbox.get_new_mail())
|
||||
self.assertNotEqual(mailbox.last_polling, None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue