[FIX] mail, purchase: avoid full cache invalidation when possible (#14934)

* [FIX] mail: avoid full cache invalidation when possible

* [FIX] purchase: avoid full cache invalidation when possible
This commit is contained in:
Raphael Collet 2017-01-12 11:31:58 +01:00 committed by GitHub
parent 6b87284f3f
commit a1be7ca551
4 changed files with 36 additions and 14 deletions

View File

@ -22,7 +22,7 @@
import threading
from openerp.osv import osv, fields
from openerp import tools, SUPERUSER_ID
from openerp import api, tools, SUPERUSER_ID
from openerp.tools.translate import _
from openerp.tools.mail import plaintext2html
@ -55,20 +55,31 @@ class mail_followers(osv.Model):
# Modifying followers change access rights to individual documents. As the
# cache may contain accessible/inaccessible data, one has to refresh it.
#
def create(self, cr, uid, vals, context=None):
res = super(mail_followers, self).create(cr, uid, vals, context=context)
self.invalidate_cache(cr, uid, context=context)
@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):
record = super(mail_followers, self).create(vals)
record._invalidate_documents()
return record
@api.multi
def write(self, vals):
if 'res_model' in vals or 'res_id' in vals:
self._invalidate_documents()
res = super(mail_followers, self).write(vals)
self._invalidate_documents()
return res
def write(self, cr, uid, ids, vals, context=None):
res = super(mail_followers, self).write(cr, uid, ids, vals, context=context)
self.invalidate_cache(cr, uid, context=context)
return res
def unlink(self, cr, uid, ids, context=None):
res = super(mail_followers, self).unlink(cr, uid, ids, context=context)
self.invalidate_cache(cr, uid, context=context)
return res
@api.multi
def unlink(self):
self._invalidate_documents()
return super(mail_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.')]

View File

@ -209,6 +209,16 @@ class test_mail(TestMail):
self.assertTrue(subtype_data['mt_mg_nodef']['followed'], 'Admin should follow mt_mg_nodef in pigs')
self.assertTrue(subtype_data['mt_all_nodef']['followed'], 'Admin should follow mt_all_nodef in pigs')
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)
def test_11_notification_url(self):
""" Tests designed to test the URL added in notification emails. """
cr, uid, group_pigs = self.cr, self.uid, self.group_pigs

View File

@ -51,6 +51,8 @@ class mail_message(osv.Model):
"""
if uid == SUPERUSER_ID:
return super(mail_message, self).check_access_rule(cr, uid, ids=ids, operation=operation, context=context)
if isinstance(ids, (int, long)):
ids = [ids]
group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_user')[1]
if group_user_id not in [group.id for group in group_ids]:

View File

@ -72,7 +72,6 @@ class purchase_order(osv.osv):
('order_id', '=', po.id), '|', ('date_planned', '=', po.minimum_planned_date), ('date_planned', '<', value)
], context=context)
pol_obj.write(cr, uid, pol_ids, {'date_planned': value}, context=context)
self.invalidate_cache(cr, uid, context=context)
return True
def _minimum_planned_date(self, cr, uid, ids, field_name, arg, context=None):