diff options
| author | Thibault Delavallée <tde@odoo.com> | 2018-04-05 14:48:19 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-04-10 11:01:16 +0200 |
| commit | 9f3889eba39fd39497208ec0a31fe8bc010a979a (patch) | |
| tree | 5e4454fa0e26f5b38374a8c0ca75ad260f36eb59 /addons/mail/models/mail_message.py | |
| parent | bcc6884737a0e172fb436dfcc199e5e1155fdc60 (diff) | |
[IMP] mail: limit cache invalidation when managing messages
This commit proposes to limit cache invalidation at some cases that will
trigger some behavior change when dealing with mail messages :
* creating messages linked to a document;
* update model or res_id of a message;
* updating notifications, as notified people could change some computed
fields on the record;
This commit also invalidates only mail-related fields as updating messages
should not invalidate other things than some computed fields linked to
mail.
Diffstat (limited to 'addons/mail/models/mail_message.py')
| -rw-r--r-- | addons/mail/models/mail_message.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index e087d745861..740425bb75e 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -717,8 +717,14 @@ class Message(models.Model): def _invalidate_documents(self): """ Invalidate the cache of the documents followed by ``self``. """ for record in self: - if record.model and record.res_id: - self.env[record.model].invalidate_cache(ids=[record.res_id]) + if record.model and record.res_id and 'message_ids' in self.env[record.model]: + self.env[record.model].invalidate_cache(fnames=[ + 'message_ids', + 'message_unread', + 'message_unread_counter', + 'message_needaction', + 'message_needaction_counter', + ], ids=[record.res_id]) @api.model def create(self, values): @@ -764,7 +770,8 @@ class Message(models.Model): if tracking_values_cmd: message.sudo().write({'tracking_value_ids': tracking_values_cmd}) - message._invalidate_documents() + if values.get('model') and values.get('res_id'): + message._invalidate_documents() return message @@ -780,7 +787,8 @@ class Message(models.Model): if 'model' in vals or 'res_id' in vals: self._invalidate_documents() res = super(Message, self).write(vals) - self._invalidate_documents() + if 'notification_ids' in vals or 'model' in vals or 'res_id' in vals: + self._invalidate_documents() return res @api.multi |
