[REF] mail: simplify parent fetch when posting a message

1d57a09112 added a two-steps parent fetch when posting a message
on a discussion thread. At the time this commit was done responsible were
notified of the first thread message. It was helpful to notify them of the
original email that created the thread instead of the "document created"
generic message. Indeed for documents like leads or issues having the
original email containing the customer question is interesting when being
notified. This is why this commit was done.

However since quite a long time responsible notifications have changed.
They now receive an email notification telling they have been assigned on
a document. This commit is not necessary anymore and we therefore remove
it in order to clean a bit the message_post process.

This commit globally reverts 1d57a09112. Please note that @beledouxdenis
agreed after a long thinking.

This commit has a slight impact on mail performance tests, allowing to save
one query in some more complex test case.
This commit is contained in:
Thibault Delavallée
2018-02-26 14:11:32 +01:00
parent 74d4b3902d
commit 97ee12e9c7
2 changed files with 6 additions and 8 deletions
+2 -4
View File
@@ -1862,10 +1862,8 @@ class MailThread(models.AbstractModel):
# _mail_flat_thread: automatically set free messages to the first posted message
MailMessage = self.env['mail.message']
if self._mail_flat_thread and model and not parent_id and self.ids:
messages = MailMessage.search(['&', ('res_id', '=', self.ids[0]), ('model', '=', model), ('message_type', '=', 'email')], order="id ASC", limit=1)
if not messages:
messages = MailMessage.search(['&', ('res_id', '=', self.ids[0]), ('model', '=', model)], order="id ASC", limit=1)
parent_id = messages and messages[0].id or False
messages = MailMessage.search(['&', ('res_id', '=', self.ids[0]), ('model', '=', model)], order="id ASC", limit=1)
parent_id = messages.ids and messages.ids[0] or False
# we want to set a parent: force to set the parent_id to the oldest ancestor, to avoid having more than 1 level of thread
elif parent_id:
messages = MailMessage.sudo().search([('id', '=', parent_id), ('parent_id', '!=', False)], limit=1)
+4 -4
View File
@@ -243,7 +243,7 @@ class TestHeavyMailPerformance(TransactionCase):
self.umbrella.message_subscribe(self.user_portal.partner_id.ids)
record = self.umbrella.sudo(self.env.user)
with self.assertQueryCount(admin=124, emp=157): # com runbot 122 - 155 // test_mail only: 118 - 150
with self.assertQueryCount(admin=123, emp=156): # com runbot 121 - 154 // test_mail only: 117 - 149
record.message_post(
body='<p>Test Post Performances</p>',
message_type='comment',
@@ -260,7 +260,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=149, emp=197): # com runbot 147 - 195 // test_mail only: 141 - 187
with self.assertQueryCount(admin=148, emp=196): # com runbot 146 - 194 // test_mail only: 140 - 186
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)
@@ -276,7 +276,7 @@ class TestHeavyMailPerformance(TransactionCase):
customer_id = self.customer.id
user_id = self.user_portal.id
with self.assertQueryCount(admin=336, emp=398): # test_mail only: 323 - 383
with self.assertQueryCount(admin=335, emp=397): # test_mail only: 322 - 382
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': umbrella_id,
@@ -315,7 +315,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
with self.assertQueryCount(admin=239, emp=279): # test_mail only: 233 - 271
with self.assertQueryCount(admin=238, emp=278): # test_mail only: 231 - 270
rec.write({
'name': 'Test2',
'umbrella_id': umbrella_id,