summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests/test_performance.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-03-02 17:48:32 +0100
committerThibault Delavallée <tde@odoo.com>2018-04-03 17:11:43 +0200
commitb6d2351df45bdd049e42e828743b5dd2f1941649 (patch)
tree40fb6f3b0f515ab538fa9f5a1a1fc7754f758e1e /addons/test_mail/tests/test_performance.py
parent301f140cb6c872e3f4303f6ce46c626d3f04fa2f (diff)
[REF] mail: improve implementation of message subscribe
This commit refactors mail.thread message_subscribe method. It is done for two purposes. First one is to optimize performance by using the new followers computation methods introduced recently. Second purpose is to clean the API of message_subscribe to make it simpler to use. This commit splits message_subscribe in two main parts : * _message_subscribe is a private method calling the follower new subscription methods and updating the record set; * message_subscribe is a public wrapper on _message_subscribe that adds access rights checks; Simplification comes by removing message_subscribe_users that was a shortcut to message_subscribe. Having a method to subscribe partners and channels is sufficient as we would like to avoid bloating the public API of mail.thread. A force parameter is also removed from message_subscribe as this implementation detail can be induced in the computation. Various addons using the removed methods are updated in order to use the new subscription API. They have the same functional behavior. This commit has a great impact when subscribing several followers. In a more general way all code using message_post is also optimized as posting a message generally implies subscribing followers. It also improves activity use as posting a message and subscribing new followers are common process in activities.
Diffstat (limited to 'addons/test_mail/tests/test_performance.py')
-rw-r--r--addons/test_mail/tests/test_performance.py50
1 files changed, 24 insertions, 26 deletions
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py
index feca36fde86..8ac43339e4a 100644
--- a/addons/test_mail/tests/test_performance.py
+++ b/addons/test_mail/tests/test_performance.py
@@ -99,7 +99,7 @@ class TestMailPerformance(TransactionCase):
@users('admin', 'emp')
@warmup
def test_create_mail_simple(self):
- with self.assertQueryCount(admin=9, emp=9): # test_mail only: 9 - 9
+ with self.assertQueryCount(admin=8, emp=8): # test_mail only: 8 - 8
self.env['mail.test.simple'].create({'name': 'Test'})
@users('admin', 'emp')
@@ -160,7 +160,7 @@ class TestAdvMailPerformance(TransactionCase):
'default_res_model': 'mail.test.activity',
})
- with self.assertQueryCount(admin=27, emp=33): # test_mail only: 26 - 32
+ with self.assertQueryCount(admin=11, emp=15): # test_mail only: 11 - 15
activity = MailActivity.create({
'summary': 'Test Activity',
'res_id': record.id,
@@ -176,7 +176,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_adv_activity_mixin(self):
record = self.env['mail.test.activity'].create({'name': 'Test'})
- with self.assertQueryCount(admin=27, emp=33): # test_mail only: 26 - 32
+ with self.assertQueryCount(admin=11, emp=15): # test_mail only: 11 - 15
record.action_start('Test Start')
record.write({'name': 'Dupe write'})
@@ -193,7 +193,7 @@ class TestAdvMailPerformance(TransactionCase):
self.user_test.write({'notification_type': 'email'})
record = self.env['mail.test.track'].create({'name': 'Test'})
- with self.assertQueryCount(admin=88, emp=115): # test_mail only: 86 - 113
+ with self.assertQueryCount(admin=86, emp=111): # test_mail only: 84 - 109
record.write({
'user_id': self.user_test.id,
})
@@ -203,7 +203,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_assignation_inbox(self):
record = self.env['mail.test.track'].create({'name': 'Test'})
- with self.assertQueryCount(admin=48, emp=63): # test_mail only: 48 - 63
+ with self.assertQueryCount(admin=47, emp=60): # com runbot 46 - 59 // test_mail only: 46 - 59
record.write({
'user_id': self.user_test.id,
})
@@ -223,7 +223,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_log_with_post(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(admin=27, emp=38): # test_mail only: 27 - 38
+ with self.assertQueryCount(admin=24, emp=34): # test_mail only: 24 - 34
record.message_post(
body='<p>Test message_post as log</p>',
subtype='mail.mt_note',
@@ -234,7 +234,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_no_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(admin=27, emp=38): # test_mail only: 27 - 38
+ with self.assertQueryCount(admin=24, emp=34): # test_mail only: 24 - 34
record.message_post(
body='<p>Test Post Performances basic</p>',
partner_ids=[],
@@ -247,7 +247,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_one_email_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(admin=78, emp=105): # com runbot 76 - 103 // test_mail only: 76 - 103
+ with self.assertQueryCount(admin=75, emp=101): # com runbot 73 - 99 // test_mail only: 73 - 99
record.message_post(
body='<p>Test Post Performances with an email ping</p>',
partner_ids=self.customer.ids,
@@ -259,7 +259,7 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_post_one_inbox_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(admin=40, emp=52): # com runbot 38 - 50 // test_mail only: 40 - 52
+ with self.assertQueryCount(admin=37, emp=48): # com runbot 35 - 46 // test_mail only: 37 - 48
record.message_post(
body='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,
@@ -272,10 +272,10 @@ class TestAdvMailPerformance(TransactionCase):
def test_message_subscribe_default(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(admin=7, emp=8): # test_mail only: 7 - 8
+ with self.assertQueryCount(admin=6, emp=6): # test_mail only: 6 - 6
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
- with self.assertQueryCount(admin=19, emp=19): # test_mail only: 19 - 19
+ with self.assertQueryCount(admin=3, emp=3): # test_mail only: 3 - 3
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
@mute_logger('odoo.models.unlink')
@@ -285,10 +285,10 @@ class TestAdvMailPerformance(TransactionCase):
record = self.env['mail.test.simple'].create({'name': 'Test'})
subtype_ids = (self.env.ref('test_mail.st_mail_test_simple_external') | self.env.ref('mail.mt_comment')).ids
- with self.assertQueryCount(admin=7, emp=8): # test_mail only: 7 - 8
+ with self.assertQueryCount(admin=5, emp=5): # test_mail only: 5 - 5
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
- with self.assertQueryCount(admin=19, emp=19): # test_mail only: 18 - 18
+ with self.assertQueryCount(admin=14, emp=14): # test_mail only: 14 - 14
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
@@ -424,35 +424,33 @@ class TestHeavyMailPerformance(TransactionCase):
self.assertEqual(rec.message_channel_ids, self.env['mail.channel'])
# subscribe new followers with forced given subtypes
- with self.assertQueryCount(admin=20, emp=21): # test_mail only: 20 - 21
+ with self.assertQueryCount(admin=16, emp=16): # test_mail only: 16 - 16
rec.message_subscribe(
partner_ids=pids[:4],
channel_ids=cids,
- subtype_ids=subtype_ids,
+ subtype_ids=subtype_ids
)
self.assertEqual(rec.message_partner_ids, self.env.user.partner_id | self.user_portal.partner_id | self.partners[:4])
self.assertEqual(rec.message_channel_ids, self.channel)
# subscribe existing and new followers with force=False, meaning only some new followers will be added
- with self.assertQueryCount(admin=11, emp=12): # test_mail only: 11 - 12
+ with self.assertQueryCount(admin=8, emp=8): # test_mail only: 8 - 8
rec.message_subscribe(
partner_ids=pids[:6],
channel_ids=cids,
- subtype_ids=None,
- force=False,
+ subtype_ids=None
)
self.assertEqual(rec.message_partner_ids, self.env.user.partner_id | self.user_portal.partner_id | self.partners[:6])
self.assertEqual(rec.message_channel_ids, self.channel)
# subscribe existing and new followers with force=True, meaning all will have the same subtypes
- with self.assertQueryCount(admin=48, emp=49): # test_mail only: 48 - 49
+ with self.assertQueryCount(admin=42, emp=43): # test_mail only: 42 - 43
rec.message_subscribe(
partner_ids=pids,
channel_ids=cids,
- subtype_ids=subtype_ids,
- force=True,
+ subtype_ids=subtype_ids
)
self.assertEqual(rec.message_partner_ids, self.env.user.partner_id | self.user_portal.partner_id | self.partners)
@@ -471,7 +469,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id)
- with self.assertQueryCount(admin=90, emp=119): # test_mail only: 88 - 117
+ with self.assertQueryCount(admin=88, emp=115): # test_mail only: 86 - 113
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)
@@ -494,7 +492,7 @@ class TestHeavyMailPerformance(TransactionCase):
customer_id = self.customer.id
user_id = self.user_portal.id
- with self.assertQueryCount(admin=318, emp=379): # com runbot: 318 - 378 // test_mail only: 311 - 372
+ with self.assertQueryCount(admin=266, emp=317): #com runbot: 266 - 316 // test_mail only: 259 - 310
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': umbrella_id,
@@ -523,7 +521,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
- with self.assertQueryCount(admin=227, emp=264): # test_mail only: 223 - 260
+ with self.assertQueryCount(admin=178, emp=205): # test_mail only: 174 - 201
rec.write({
'name': 'Test2',
'umbrella_id': self.umbrella.id,
@@ -561,7 +559,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
- with self.assertQueryCount(admin=230, emp=268): # test_mail only: 225 - 264
+ with self.assertQueryCount(admin=181, emp=210): # test_mail only: 176 - 205
rec.write({
'name': 'Test2',
'umbrella_id': umbrella_id,
@@ -595,7 +593,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=63, emp=90): # test_mail only: 61 - 88
+ with self.assertQueryCount(admin=61, emp=86): # test_mail only: 59 - 84
rec.write({
'name': 'Test2',
'customer_id': customer_id,