summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-03-28 14:15:11 +0200
committerThibault Delavallée <tde@odoo.com>2018-03-28 16:57:05 +0200
commit4451e505cd9505ddd862b4312daec26089e9c7d1 (patch)
treede95a57b75017ad9d9b2d26138a7314e2fc822d9
parenta2511f3a5aeb0ea33c52f96d785f2d8f4da847dc (diff)
[IMP] mail: use xmlid_to_res_id instead of ref in remaining places of mail
As explained in previous commit we can use xmlid_to_res_id instead of ref() which leads to some query gain. This commit update some other less important places: when setting activities as done and in the composer. This lead to a gain in tests involving activities and composer, including tracking triggering a template. On community runbot this leads to a gain of about 1K queries.
-rw-r--r--addons/mail/models/mail_activity.py2
-rw-r--r--addons/mail/wizard/mail_compose_message.py4
-rw-r--r--addons/test_mail/tests/test_performance.py8
3 files changed, 7 insertions, 7 deletions
diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py
index 0f849526b90..2d252f911c4 100644
--- a/addons/mail/models/mail_activity.py
+++ b/addons/mail/models/mail_activity.py
@@ -300,7 +300,7 @@ class MailActivity(models.Model):
record.message_post_with_view(
'mail.message_activity_done',
values={'activity': activity},
- subtype_id=self.env.ref('mail.mt_activities').id,
+ subtype_id=self.env['ir.model.data'].xmlid_to_res_id('mail.mt_activities'),
mail_activity_type_id=activity.activity_type_id.id,
)
message |= record.message_ids[0]
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 573e54898b4..4cc06574ec4 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -123,7 +123,7 @@ class MailComposer(models.TransientModel):
domain="[('model', '=', model)]")
# mail_message updated fields
message_type = fields.Selection(default="comment")
- subtype_id = fields.Many2one(default=lambda self: self.sudo().env.ref('mail.mt_comment', raise_if_not_found=False).id)
+ subtype_id = fields.Many2one(default=lambda self: self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment'))
@api.multi
def check_access_rule(self, operation):
@@ -239,7 +239,7 @@ class MailComposer(models.TransientModel):
elif wizard.subtype_id:
subtype_id = wizard.subtype_id.id
else:
- subtype_id = self.sudo().env.ref('mail.mt_comment', raise_if_not_found=False).id
+ subtype_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment')
for res_ids in sliced_res_ids:
batch_mails = Mail
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py
index cb392019f0b..b8e3b71d249 100644
--- a/addons/test_mail/tests/test_performance.py
+++ b/addons/test_mail/tests/test_performance.py
@@ -167,7 +167,7 @@ class TestAdvMailPerformance(TransactionCase):
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
})
- with self.assertQueryCount(admin=58, emp=87): # test_mail only: 57 - 86
+ with self.assertQueryCount(admin=57, emp=86): # test_mail only: 56 - 85
activity.action_feedback(feedback='Zizisse Done !')
@users('admin', 'emp')
@@ -181,7 +181,7 @@ class TestAdvMailPerformance(TransactionCase):
record.write({'name': 'Dupe write'})
- with self.assertQueryCount(admin=58, emp=87): # test_mail only: 57 - 86
+ with self.assertQueryCount(admin=57, emp=86): # test_mail only: 56 - 85
record.action_close('Dupe feedback')
self.assertEqual(record.activity_ids, self.env['mail.activity'])
@@ -399,7 +399,7 @@ class TestHeavyMailPerformance(TransactionCase):
record = self.umbrella.sudo(self.env.user)
template_id = self.env.ref('test_mail.mail_test_tpl').id
- with self.assertQueryCount(admin=139, emp=184): # com runbot 137 - 182 // test_mail only: 135 - 180
+ with self.assertQueryCount(admin=138, emp=183): # com runbot 136 - 181 // test_mail only: 134 - 179
record.message_post_with_template(template_id, message_type='comment', composition_mode='comment')
self.assertEqual(record.message_ids[0].body, '<p>Adding stuff on %s</p>' % record.name)
@@ -595,7 +595,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
- with self.assertQueryCount(admin=64, emp=91): # test_mail only: 62 - 89
+ with self.assertQueryCount(admin=63, emp=90): # test_mail only: 61 - 88
rec.write({
'name': 'Test2',
'customer_id': customer_id,