← Back to team overview

credativ team mailing list archive

[Branch ~credativ/openobject-addons/6.1] Rev 7080: [IMP] Database cursor efficiency when sending emails

 

------------------------------------------------------------
revno: 7080
committer: Tom Pickering <tom.pickering@xxxxxxxxxxxxxx>
branch nick: 6.1
timestamp: Wed 2016-09-07 16:32:51 +0100
message:
  [IMP] Database cursor efficiency when sending emails
modified:
  mail/mail_message.py


--
lp:~credativ/openobject-addons/6.1
https://code.launchpad.net/~credativ/openobject-addons/6.1

Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.1.
To unsubscribe from this branch go to https://code.launchpad.net/~credativ/openobject-addons/6.1/+edit-subscription
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2016-09-07 09:13:19 +0000
+++ mail/mail_message.py	2016-09-07 15:32:51 +0000
@@ -510,8 +510,8 @@
         if context is None:
             context = {}
         ir_mail_server = self.pool.get('ir.mail_server')
-        for msg_id in ids:
-            with closing(pooler.get_db(cr.dbname).cursor()) as _cr:
+        with closing(pooler.get_db(cr.dbname).cursor()) as _cr:
+            for msg_id in ids:
                 try:
                     _cr.execute('SELECT * FROM mail_message WHERE id = %s FOR UPDATE NOWAIT', [msg_id])
                     message = self.browse(_cr, uid, msg_id, context=context)
@@ -566,10 +566,11 @@
 
                     _cr.commit()
                 except MailTransientDeliveryException:
-                    pass
+                    _cr.rollback()
                 except OperationalError:
+                    _cr.rollback()
                     _logger.exception('failed sending mail.message %s and unable to update state', msg_id)
-                    # We can't use this cursor any more - attempting to updating
+                    # We can't use this cursor any more - attempting to update
                     # the message state will just throw a new exception.
                 except Exception:
                     _logger.exception('failed sending mail.message %s', msg_id)