diff options
Diffstat (limited to 'addons/mail/models/mail_thread.py')
| -rw-r--r-- | addons/mail/models/mail_thread.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index e247df26c8f..587009984cf 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -120,7 +120,8 @@ class MailThread(models.AbstractModel): followers = self.env['mail.followers'].sudo().search([ ('res_model', '=', self._name), ('partner_id', operator, operand)]) - return [('id', 'in', followers.mapped('res_id'))] + # using read() below is much faster than followers.mapped('res_id') + return [('id', 'in', [res['res_id'] for res in followers.read(['res_id'])])] @api.model def _search_follower_channels(self, operator, operand): @@ -133,7 +134,8 @@ class MailThread(models.AbstractModel): followers = self.env['mail.followers'].sudo().search([ ('res_model', '=', self._name), ('channel_id', operator, operand)]) - return [('id', 'in', followers.mapped('res_id'))] + # using read() below is much faster than followers.mapped('res_id') + return [('id', 'in', [res['res_id'] for res in followers.read(['res_id'])])] @api.multi @api.depends('message_follower_ids') @@ -143,7 +145,8 @@ class MailThread(models.AbstractModel): ('res_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id), ]) - following_ids = followers.mapped('res_id') + # using read() below is much faster than followers.mapped('res_id') + following_ids = [res['res_id'] for res in followers.read(['res_id'])] for record in self: record.message_is_follower = record.id in following_ids @@ -155,9 +158,11 @@ class MailThread(models.AbstractModel): ]) # Cases ('message_is_follower', '=', True) or ('message_is_follower', '!=', False) if (operator == '=' and operand) or (operator == '!=' and not operand): - return [('id', 'in', followers.mapped('res_id'))] + # using read() below is much faster than followers.mapped('res_id') + return [('id', 'in', [res['res_id'] for res in followers.read(['res_id'])])] else: - return [('id', 'not in', followers.mapped('res_id'))] + # using read() below is much faster than followers.mapped('res_id') + return [('id', 'not in', [res['res_id'] for res in followers.read(['res_id'])])] @api.multi def _get_message_unread(self): @@ -1433,7 +1438,13 @@ class MailThread(models.AbstractModel): located in tools. """ if not body: return body, attachments - root = lxml.html.fromstring(body) + try: + root = lxml.html.fromstring(body) + except ValueError: + # In case the email client sent XHTML, fromstring will fail because 'Unicode strings + # with encoding declaration are not supported'. + root = lxml.html.fromstring(body.encode('utf-8')) + postprocessed = False to_remove = [] for node in root.iter(): @@ -1815,6 +1826,8 @@ class MailThread(models.AbstractModel): continue if isinstance(content, pycompat.text_type): content = content.encode('utf-8') + elif content is None: + continue data_attach = { 'name': name, 'datas': base64.b64encode(content), |
