summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests/test_performance.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-04-05 12:51:21 +0200
committerThibault Delavallée <tde@odoo.com>2018-04-10 11:00:41 +0200
commitbcc6884737a0e172fb436dfcc199e5e1155fdc60 (patch)
tree8f2d1ea413e06ac16670127fcdfdefdce1a18ead /addons/test_mail/tests/test_performance.py
parent26d110c4727d3c423672044164a51c02671d2797 (diff)
[IMP] mail: limit cache invalidation when subscribing followers
Cache invalidation when subscribing people has been added at e6f038a8216c249a3ce7d9f490010d9f666f3375. Indeed subscribing partners to a record may lead to an access right update as some of them are based on followers. This is why a cache invalidation is necessary to avoid access rights issues. However subscribing people to a record should change their rights only on the records involved in the subscription mechanism. We can therefore give ids to the cache invalidation to limit to updated records. Cache invalidation is also limited when writing on followers if writing on model, res_id or partner_id fields. Indeed changing subtypes or channel of a subscription should have no impact on cache and access rights. Cache invalidation done manually in _message_subscribe is not necessary as subscription create or update mail.followers records since f9c210923d89aeabfc358fdc7b8bd76df8c23ce8. Create and write of mail.followers records already ask for cache invalidation. It is therefore not necessary to invalidate cache twice. This commit allows to save a few queries on some tests, notably about activities that deal with subscription and messages. As cache is now kept it is not necessary to refetch some data, leading to a few query gain. We gain about 1K queries on com runbot. A side effect of limiting cache invalidation is that some unit tests require a manual cache invalidation to have up to date results. Indeed record not being up to date in cache was hidden by the invalidation we just removed.
Diffstat (limited to 'addons/test_mail/tests/test_performance.py')
-rw-r--r--addons/test_mail/tests/test_performance.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py
index cfc78926bad..91c6017ef4b 100644
--- a/addons/test_mail/tests/test_performance.py
+++ b/addons/test_mail/tests/test_performance.py
@@ -160,14 +160,14 @@ class TestAdvMailPerformance(TransactionCase):
'default_res_model': 'mail.test.activity',
})
- with self.assertQueryCount(admin=11, emp=15): # test_mail only: 11 - 15
+ with self.assertQueryCount(admin=9, emp=13): # test_mail only: 9 - 13
activity = MailActivity.create({
'summary': 'Test Activity',
'res_id': record.id,
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
})
- with self.assertQueryCount(margin=1, admin=53, emp=77): # test_mail only: 53 - 77
+ with self.assertQueryCount(margin=1, admin=49, emp=73): # test_mail only: 49 - 73
activity.action_feedback(feedback='Zizisse Done !')
@users('admin', 'emp')
@@ -176,12 +176,12 @@ class TestAdvMailPerformance(TransactionCase):
def test_adv_activity_mixin(self):
record = self.env['mail.test.activity'].create({'name': 'Test'})
- with self.assertQueryCount(admin=11, emp=15): # test_mail only: 11 - 15
+ with self.assertQueryCount(admin=9, emp=13): # test_mail only: 9 - 13
record.action_start('Test Start')
record.write({'name': 'Dupe write'})
- with self.assertQueryCount(margin=1, admin=53, emp=78): # test_mail only: 53 - 78
+ with self.assertQueryCount(margin=1, admin=51, emp=75): # test_mail only: 51 - 75
record.action_close('Dupe feedback')
self.assertEqual(record.activity_ids, self.env['mail.activity'])
@@ -275,7 +275,7 @@ class TestAdvMailPerformance(TransactionCase):
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=3, emp=3): # test_mail only: 3 - 3
+ with self.assertQueryCount(admin=2, emp=2): # test_mail only: 2 - 2
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
@mute_logger('odoo.models.unlink')
@@ -288,7 +288,7 @@ class TestAdvMailPerformance(TransactionCase):
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=14, emp=14): # test_mail only: 14 - 14
+ with self.assertQueryCount(admin=12, emp=12): # test_mail only: 12 - 12
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
@@ -382,7 +382,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=115, emp=144): # com runbot 113 - 142 // test_mail only: 111 - 140
+ with self.assertQueryCount(admin=114, emp=143): # com runbot 112 - 141 // test_mail only: 110 - 139
record.message_post(
body='<p>Test Post Performances</p>',
message_type='comment',
@@ -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=137, emp=179): # com runbot 135 - 177 // test_mail only: 133 - 175
+ with self.assertQueryCount(admin=136, emp=178): # com runbot 134 - 176 // test_mail only: 132 - 174
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)
@@ -446,7 +446,7 @@ class TestHeavyMailPerformance(TransactionCase):
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=42, emp=43): # test_mail only: 42 - 43
+ with self.assertQueryCount(admin=42, emp=42): # test_mail only: 42 - 42
rec.message_subscribe(
partner_ids=pids,
channel_ids=cids,
@@ -492,7 +492,7 @@ class TestHeavyMailPerformance(TransactionCase):
customer_id = self.customer.id
user_id = self.user_portal.id
- with self.assertQueryCount(admin=235, emp=282): # test_mail only: 228 - 275
+ with self.assertQueryCount(margin=1, admin=235, emp=284): # test_mail only: 228 - 277
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': umbrella_id,
@@ -521,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=148, emp=171): # test_mail only: 143 - 166
+ with self.assertQueryCount(admin=147, emp=172): # test_mail only: 143 - 167
rec.write({
'name': 'Test2',
'umbrella_id': self.umbrella.id,
@@ -559,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=152, emp=178): # test_mail only: 147 - 173
+ with self.assertQueryCount(admin=152, emp=180): # test_mail only: 147 - 175
rec.write({
'name': 'Test2',
'umbrella_id': umbrella_id,