summaryrefslogtreecommitdiff
path: root/addons/mail
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-01-17 18:04:57 +0100
committerChristophe Simonis <chs@odoo.com>2017-01-17 18:04:57 +0100
commit70f86ce4e8f4570f8a8b18e012b9af5326a5ce2a (patch)
tree9ce23bce7bb979fa29c416aad21c14300903579f /addons/mail
parentc61e359fad9fdc2e7658a3e9f584fc40e0cfecf6 (diff)
parent16fa61b34f919a39dc4094b74d77ab5ac054dc5e (diff)
[MERGE] forward port branch 9.0 up to 16fa61b34f9
Diffstat (limited to 'addons/mail')
-rw-r--r--addons/mail/models/mail_followers.py18
-rw-r--r--addons/mail/models/mail_message.py17
-rw-r--r--addons/mail/tests/test_mail_features.py11
-rw-r--r--addons/mail/tests/test_mail_message.py5
4 files changed, 46 insertions, 5 deletions
diff --git a/addons/mail/models/mail_followers.py b/addons/mail/models/mail_followers.py
index 6c066b123dd..14c1cbddbda 100644
--- a/addons/mail/models/mail_followers.py
+++ b/addons/mail/models/mail_followers.py
@@ -112,23 +112,31 @@ class Followers(models.Model):
# Modifying followers change access rights to individual documents. As the
# cache may contain accessible/inaccessible data, one has to refresh it.
#
+ @api.multi
+ def _invalidate_documents(self):
+ """ Invalidate the cache of the documents followed by ``self``. """
+ for record in self:
+ if record.res_id:
+ self.env[record.res_model].invalidate_cache(ids=[record.res_id])
+
@api.model
def create(self, vals):
res = super(Followers, self).create(vals)
- self.invalidate_cache()
+ res._invalidate_documents()
return res
@api.multi
def write(self, vals):
+ if 'res_model' in vals or 'res_id' in vals:
+ self._invalidate_documents()
res = super(Followers, self).write(vals)
- self.invalidate_cache()
+ self._invalidate_documents()
return res
@api.multi
def unlink(self):
- res = super(Followers, self).unlink()
- self.invalidate_cache()
- return res
+ self._invalidate_documents()
+ return super(Followers, self).unlink()
_sql_constraints = [
('mail_followers_res_partner_res_model_id_uniq', 'unique(res_model,res_id,partner_id)', 'Error, a partner cannot follow twice the same object.'),
diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py
index e927d84ca0c..c6d306c65a9 100644
--- a/addons/mail/models/mail_message.py
+++ b/addons/mail/models/mail_message.py
@@ -854,6 +854,13 @@ class Message(models.Model):
message_id = tools.generate_tracking_message_id('private')
return message_id
+ @api.multi
+ def _invalidate_documents(self):
+ """ Invalidate the cache of the documents followed by ``self``. """
+ for record in self:
+ if record.res_id:
+ self.env[record.model].invalidate_cache(ids=[record.res_id])
+
@api.model
def create(self, values):
# coming from mail.js that does not have pid in its values
@@ -870,6 +877,7 @@ class Message(models.Model):
values['record_name'] = self._get_record_name(values)
message = super(Message, self).create(values)
+ message._invalidate_documents()
message._notify(force_send=self.env.context.get('mail_notify_force_send', True),
user_signature=self.env.context.get('mail_notify_user_signature', True))
@@ -883,6 +891,14 @@ class Message(models.Model):
return super(Message, self).read(fields=fields, load=load)
@api.multi
+ def write(self, vals):
+ if 'model' in vals or 'res_id' in vals:
+ self._invalidate_documents()
+ res = super(Message, self).write(vals)
+ self._invalidate_documents()
+ return res
+
+ @api.multi
def unlink(self):
# cascade-delete attachments that are directly attached to the message (should only happen
# for mail.messages that act as parent for a standalone mail.mail record).
@@ -890,6 +906,7 @@ class Message(models.Model):
self.mapped('attachment_ids').filtered(
lambda attach: attach.res_model == self._name and (attach.res_id in self.ids or attach.res_id == 0)
).unlink()
+ self._invalidate_documents()
return super(Message, self).unlink()
#------------------------------------------------------
diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py
index 2766d0d7ced..82dc2e05363 100644
--- a/addons/mail/tests/test_mail_features.py
+++ b/addons/mail/tests/test_mail_features.py
@@ -25,6 +25,17 @@ class TestMailFeatures(TestMail):
'login': 'b4r+_#_R3wl$$', 'alias_name': 'b4r+_#_R3wl$$'})
self.assertEqual(user_barty.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens')
+ def test_10_cache_invalidation(self):
+ """ Test that creating a mail-thread record does not invalidate the whole cache. """
+ # make a new record in cache
+ record = self.env['res.partner'].new({'name': 'Brave New Partner'})
+ self.assertTrue(record.name)
+
+ # creating a mail-thread record should not invalidate the whole cache
+ self.env['res.partner'].create({'name': 'Actual Partner'})
+ self.assertTrue(record.name)
+
+
@mute_logger('openerp.addons.mail.models.mail_mail')
def test_needaction(self):
na_emp1_base = self.env['mail.message'].sudo(self.user_employee)._needaction_count(domain=[])
diff --git a/addons/mail/tests/test_mail_message.py b/addons/mail/tests/test_mail_message.py
index 6407d97c9cf..2be7537ce75 100644
--- a/addons/mail/tests/test_mail_message.py
+++ b/addons/mail/tests/test_mail_message.py
@@ -251,3 +251,8 @@ class TestMailMessage(TestMail):
msg.toggle_message_starred()
self.assertFalse(msg.starred)
self.assertTrue(msg_emp.starred)
+
+ def test_60_cache_invalidation(self):
+ msg_cnt = len(self.group_pigs.message_ids)
+ self.group_pigs.message_post(body='Hi!', subject='test')
+ self.assertEqual(len(self.group_pigs.message_ids), msg_cnt + 1)