[REF] mail: shortcut chat notification if no one to notify

Well, it seems we gain a lot of query when avoiding to format a message we
actually don't have to send on any bus. Cheers.

Formatting message for bus notification is quite costly as it has to fetch
data from message, partner, attachments, subtypes, ... meaning a lot of
queries. With this commit we avoid calling that method when not necessary.

It allows a gain of queries in simple cases when no-one has to be notified
as shown in the performance counters. On overall community runbot about 9K
queries are saved which is not bad for a 2-lines commit.
This commit is contained in:
Thibault Delavallée
2018-05-02 11:39:57 +02:00
parent c832452590
commit 058d2fd4f6
2 changed files with 15 additions and 13 deletions
+2
View File
@@ -232,6 +232,8 @@ class Partner(models.Model):
@api.multi
def _notify_by_chat(self, message):
""" Broadcast the message to all the partner since """
if not self:
return
message_values = message.message_format()[0]
notifications = []
for partner in self:
+13 -13
View File
@@ -170,7 +170,7 @@ class TestAdvMailPerformance(TransactionCase):
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
})
with self.assertQueryCount(margin=1, admin=49, emp=73): # test_mail only: 49 - 73
with self.assertQueryCount(margin=1, admin=37, emp=58): # test_mail only: 37 - 58
activity.action_feedback(feedback='Zizisse Done !')
@users('admin', 'emp')
@@ -184,7 +184,7 @@ class TestAdvMailPerformance(TransactionCase):
record.write({'name': 'Dupe write'})
with self.assertQueryCount(margin=1, admin=51, emp=75): # test_mail only: 51 - 75
with self.assertQueryCount(margin=1, admin=39, emp=60): # test_mail only: 39 - 60
record.action_close('Dupe feedback')
self.assertEqual(record.activity_ids, self.env['mail.activity'])
@@ -196,7 +196,7 @@ class TestAdvMailPerformance(TransactionCase):
self.user_test.write({'notification_type': 'email'})
record = self.env['mail.test.track'].create({'name': 'Test'})
with self.assertQueryCount(margin=1, admin=81, emp=105): # test_mail only: 79 - 103
with self.assertQueryCount(margin=1, admin=68, emp=87): # com runbot: 67 - 85 // test_mail only: 66 - 85
record.write({
'user_id': self.user_test.id,
})
@@ -226,7 +226,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_log_with_post(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=24, emp=34): # test_mail only: 24 - 34
with self.assertQueryCount(admin=15, emp=29): # com runbot: 13 - 20 // test_mail only: 15 - 29
record.message_post(
body='<p>Test message_post as log</p>',
subtype='mail.mt_note',
@@ -237,7 +237,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_no_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=24, emp=34): # test_mail only: 24 - 34
with self.assertQueryCount(admin=15, emp=29): # com runbot: 13 - 20 // test_mail only: 15 - 29
record.message_post(
body='<p>Test Post Performances basic</p>',
partner_ids=[],
@@ -250,7 +250,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_one_email_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(margin=1, admin=74, emp=99): # com runbot: 72 - 97 // test_mail only: 72 - 97
with self.assertQueryCount(margin=1, admin=66, emp=89): # com runbot: 57 - 75 // test_mail only: 64 - 87
record.message_post(
body='<p>Test Post Performances with an email ping</p>',
partner_ids=self.customer.ids,
@@ -385,7 +385,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=114, emp=143): # com runbot 112 - 141 // test_mail only: 110 - 139
with self.assertQueryCount(admin=105, emp=136): # com runbot 96 - 118 // test_mail only: 101 - 132
record.message_post(
body='<p>Test Post Performances</p>',
message_type='comment',
@@ -402,7 +402,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=133, emp=174): # com runbot 131 - 172 // test_mail only: 129 - 170
with self.assertQueryCount(admin=124, emp=167): # com runbot 115 - 150 // test_mail only: 120 - 163
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)
@@ -472,7 +472,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id)
with self.assertQueryCount(admin=82, emp=108): # test_mail only: 80 - 106
with self.assertQueryCount(admin=70, emp=91): # com runbot: 69 - 89 // test_mail only: 68 - 89
rec.write({'user_id': self.user_portal.id})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
@@ -495,7 +495,7 @@ class TestHeavyMailPerformance(TransactionCase):
customer_id = self.customer.id
user_id = self.user_portal.id
with self.assertQueryCount(margin=1, admin=235, emp=284): # test_mail only: 228 - 277
with self.assertQueryCount(margin=1, admin=205, emp=244): # com runbot: 203 - 239 // test_mail only: 199 - 239
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': umbrella_id,
@@ -524,7 +524,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
with self.assertQueryCount(admin=147, emp=172): # test_mail only: 142 - 167
with self.assertQueryCount(margin=1, admin=130, emp=151): # com runbot: 129 - 148 // test_mail only: 126 - 147
rec.write({
'name': 'Test2',
'umbrella_id': self.umbrella.id,
@@ -562,7 +562,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
with self.assertQueryCount(admin=152, emp=180): # test_mail only: 147 - 175
with self.assertQueryCount(margin=1, admin=136, emp=159): # com runbot: 136 - 158 // test_mail only: 132 - 155
rec.write({
'name': 'Test2',
'umbrella_id': umbrella_id,
@@ -596,7 +596,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=57, emp=78): # test_mail only: 55 - 76
with self.assertQueryCount(admin=58, emp=79): # test_mail only: 56 - 77
rec.write({
'name': 'Test2',
'customer_id': customer_id,