summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-03-06 10:50:53 +0000
committerSébastien Theys <seb@odoo.com>2020-03-06 16:15:44 +0000
commit2490676e16964eaaf5a7c5ecb2525883c15dc6ab (patch)
tree20fa9290563a92e36ed3a704ecf4158ab6e0180c
parent04fda71e425d44d7142003d57ecc7c4e1fd3d99b (diff)
[IMP] mail, test_mail: simplify subtype in `message_format`
This makes the method easier to follow and does not increase the query count. It actually reduces it when the subtype data were already in the cache, by not always reading them again. Part of task-2180311 PR: #43841
-rw-r--r--addons/mail/models/mail_message.py12
-rw-r--r--addons/test_mail/tests/test_performance.py12
2 files changed, 9 insertions, 15 deletions
diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py
index 606d30cd4a0..21d92b5193e 100644
--- a/addons/mail/models/mail_message.py
+++ b/addons/mail/models/mail_message.py
@@ -1095,12 +1095,6 @@ class Message(models.Model):
message_tree = dict((m.id, m) for m in self.sudo())
self._message_read_dict_postprocess(message_values, message_tree)
- # add subtype data (is_note flag, is_discussion flag , subtype_description). Do it as sudo
- # because portal / public may have to look for internal subtypes
- subtype_ids = [msg['subtype_id'][0] for msg in message_values if msg['subtype_id']]
- subtypes = self.env['mail.message.subtype'].sudo().browse(subtype_ids).read(['internal', 'description','id'])
- subtypes_dict = dict((subtype['id'], subtype) for subtype in subtypes)
-
com_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment')
note_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_note')
@@ -1110,9 +1104,9 @@ class Message(models.Model):
message.update({
'needaction_partner_ids': notifs.filtered(lambda n: not n.is_read).res_partner_id.ids,
'history_partner_ids': notifs.filtered(lambda n: n.is_read).res_partner_id.ids,
- 'is_note': message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == note_id,
- 'is_discussion': message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['id'] == com_id,
- 'subtype_description': message['subtype_id'] and subtypes_dict[message['subtype_id'][0]]['description']
+ 'is_note': message_sudo.subtype_id.id == note_id,
+ 'is_discussion': message_sudo.subtype_id.id == com_id,
+ 'subtype_description': message_sudo.subtype_id.description
})
message['is_notification'] = message['message_type'] == 'user_notification'
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py
index 135db277b0c..61c2b96a61a 100644
--- a/addons/test_mail/tests/test_performance.py
+++ b/addons/test_mail/tests/test_performance.py
@@ -267,7 +267,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
'partner_ids': [(4, customer_id)],
})
- with self.assertQueryCount(__system__=34, emp=39):
+ with self.assertQueryCount(__system__=33, emp=38):
composer.send_mail()
@users('__system__', 'emp')
@@ -286,7 +286,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
}).create({})
composer.onchange_template_id_wrapper()
- with self.assertQueryCount(__system__=42, emp=46):
+ with self.assertQueryCount(__system__=41, emp=45):
composer.send_mail()
# remove created partner to ensure tests are the same each run
@@ -307,7 +307,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
@warmup
def test_message_assignation_inbox(self):
record = self.env['mail.test.track'].create({'name': 'Test'})
- with self.assertQueryCount(__system__=23, emp=25):
+ with self.assertQueryCount(__system__=22, emp=24):
record.write({
'user_id': self.user_test.id,
})
@@ -363,7 +363,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
def test_message_post_one_inbox_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
- with self.assertQueryCount(__system__=18, emp=20):
+ with self.assertQueryCount(__system__=17, emp=19):
record.message_post(
body='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,
@@ -794,7 +794,7 @@ class TestMailComplexPerformance(BaseMailPerformance):
]
}])
- with self.assertQueryCount(emp=10):
+ with self.assertQueryCount(emp=9):
res = messages.message_format()
self.assertEqual(len(res), 2)
for message in res:
@@ -803,7 +803,7 @@ class TestMailComplexPerformance(BaseMailPerformance):
messages.flush()
messages.invalidate_cache()
- with self.assertQueryCount(emp=19):
+ with self.assertQueryCount(emp=18):
res = messages.message_format()
self.assertEqual(len(res), 2)
for message in res: