[FIX] remove handling of parameters in ormcache clearing
authorXavier Morel <xmo@openerp.com>
Thu, 24 Oct 2013 13:29:56 +0000 (15:29 +0200)
committerXavier Morel <xmo@openerp.com>
Thu, 24 Oct 2013 13:29:56 +0000 (15:29 +0200)
It's completely broken in case of optional parameters
e.g. (ir.translation)._get_source, as a call with the optional
parameter won't be matched by a clear without, and the other way
around. This becomes even more problematic in the website branch as
_get_source now has *two* optional parameters (source and res_id).

After discussion with odo and discovery that in multiprocess only the
current node will use any granularity (other nodes not only clear all
of the current method cache, but all caches of all models), simplify
cache clearing, ignore parameters and just blow the current method's
cache entirely.

bzr revid: xmo@openerp.com-20131024132956-4tl3prum8za47igy

openerp/addons/base/ir/ir_model.py
openerp/addons/base/ir/ir_translation.py
openerp/tools/cache.py

index 396de27..c913af3 100644 (file)
@@ -933,8 +933,8 @@ class ir_model_data(osv.osv):
             results = cr.fetchall()
             for imd_id2,res_id2,real_id2,real_model in results:
                 if not real_id2:
-                    self._get_id.clear_cache(self, uid, module, xml_id)
-                    self.get_object_reference.clear_cache(self, uid, module, xml_id)
+                    self._get_id.clear_cache(self)
+                    self.get_object_reference.clear_cache(self)
                     cr.execute('delete from ir_model_data where id=%s', (imd_id2,))
                     res_id = False
                 else:
index 9eab451..f368308 100644 (file)
@@ -268,13 +268,8 @@ class ir_translation(osv.osv):
         return translations
 
     def _set_ids(self, cr, uid, name, tt, lang, ids, value, src=None):
-        # clear the caches
-        tr = self._get_ids(cr, uid, name, tt, lang, ids)
-        for res_id in tr:
-            if tr[res_id]:
-                self._get_source.clear_cache(self, uid, name, tt, lang, tr[res_id])
-            self._get_ids.clear_cache(self, uid, name, tt, lang, res_id)
-        self._get_source.clear_cache(self, uid, name, tt, lang)
+        self._get_ids.clear_cache(self)
+        self._get_source.clear_cache(self)
 
         cr.execute('delete from ir_translation '
                 'where lang=%s '
@@ -346,8 +341,8 @@ class ir_translation(osv.osv):
         if context is None:
             context = {}
         ids = super(ir_translation, self).create(cr, uid, vals, context=context)
-        self._get_source.clear_cache(self, uid, vals.get('name',0), vals.get('type',0),  vals.get('lang',0), vals.get('src',0))
-        self._get_ids.clear_cache(self, uid, vals.get('name',0), vals.get('type',0), vals.get('lang',0), vals.get('res_id',0))
+        self._get_source.clear_cache(self)
+        self._get_ids.clear_cache(self)
         return ids
 
     def write(self, cursor, user, ids, vals, context=None):
@@ -360,9 +355,8 @@ class ir_translation(osv.osv):
         if vals.get('value'):
             vals.update({'state':'translated'})
         result = super(ir_translation, self).write(cursor, user, ids, vals, context=context)
-        for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
-            self._get_source.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['src'])
-            self._get_ids.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['res_id'])
+        self._get_source.clear_cache(self)
+        self._get_ids.clear_cache(self)
         return result
 
     def unlink(self, cursor, user, ids, context=None):
@@ -370,9 +364,9 @@ class ir_translation(osv.osv):
             context = {}
         if isinstance(ids, (int, long)):
             ids = [ids]
-        for trans_obj in self.read(cursor, user, ids, ['name','type','res_id','src','lang'], context=context):
-            self._get_source.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['src'])
-            self._get_ids.clear_cache(self, user, trans_obj['name'], trans_obj['type'], trans_obj['lang'], trans_obj['res_id'])
+
+        self._get_source.clear_cache(self)
+        self._get_ids.clear_cache(self)
         result = super(ir_translation, self).unlink(cursor, user, ids, context=context)
         return result
 
index 4b4dcea..268ef0f 100644 (file)
@@ -1,4 +1,7 @@
 import lru
+import logging
+
+logger = logging.getLogger(__name__)
 
 class ormcache(object):
     """ LRU cache decorator for orm methods,
@@ -54,15 +57,11 @@ class ormcache(object):
         """
         d = self.lru(self2)
         if args:
-            try:
-                key = args[self.skiparg-2:]
-                del d[key]
-                self2.pool._any_cache_cleared = True
-            except KeyError:
-                pass
-        else:
-            d.clear()
-            self2.pool._any_cache_cleared = True
+            logger.warn("ormcache.clear arguments are deprecated and ignored "
+                        "(while clearing caches on (%s).%s)",
+                        self2._name, self.method.__name__)
+        d.clear()
+        self2.pool._any_cache_cleared = True
 
 class ormcache_multi(ormcache):
     def __init__(self, skiparg=2, size=8192, multi=3):