From 9de087a2380593c5008dd2944b2a4b04caf35259 Mon Sep 17 00:00:00 2001 From: "ced@b2ck.com" Date: Thu, 27 Dec 2007 23:42:01 +0100 Subject: [PATCH] Add cache and md5 on fields_view_get --- trytond/ir/ui/view.py | 40 ++++++++++++++++++++++++++++++++++++++++ trytond/osv/orm.py | 9 ++++++++- trytond/tools/misc.py | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index d28f5807ee..1d7aae904f 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -42,6 +42,46 @@ class View(OSV): (_check_xml, 'Invalid XML for View Architecture!', ['arch']) ] + def unlink(self, cursor, user, ids, context=None): + views = self.browse(cursor, user, ids, context=context) + for view in views: + # Restart the cache + try: + self.pool.get(view.model).fields_view_get() + except: + pass + res = super(View, self).unlink(cursor, user, ids, context=context) + return res + + def create(self, cursor, user, vals, context=None): + res = super(View, self).create(cursor, user, vals, context=context) + if 'model' in vals: + model = vals['model'] + # Restart the cache + try: + self.pool.get(model).fields_view_get() + except: + pass + return res + + def write(self, cursor, user, ids, vals, context=None): + views = self.browse(cursor, user, ids) + for view in views: + # Restart the cache + try: + self.pool.get(view.model).fields_view_get() + except: + pass + res = super(View, self).write(cursor, user, ids, vals, context=context) + views = self.browse(cursor, user, ids) + for view in views: + # Restart the cache + try: + self.pool.get(view.model).fields_view_get() + except: + pass + return res + View() diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index 44c695c9e7..4386770198 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -4,6 +4,8 @@ from xml.dom import minidom from xml import xpath from trytond.netsvc import Logger, LOG_ERROR, LOG_WARNING, LocalService import fields +from trytond.tools import Cache +import md5 ID_MAX = 1000 @@ -1645,7 +1647,7 @@ class ORM(object): return arch, fields2 def fields_view_get(self, cursor, user, view_id=None, view_type='form', - context=None, toolbar=False): + context=None, toolbar=False, hexmd5=None): def _inherit_apply(src, inherit): @@ -1815,8 +1817,13 @@ class ORM(object): 'action': resaction, 'relate': resrelate, } + result['md5'] = md5.new(str(result)).hexdigest() + if hexmd5 == result['md5']: + return True return result + fields_view_get = Cache()(fields_view_get) + _view_look_dom_arch = __view_look_dom_arch def _where_calc(self, cursor, user, args, active_test=True, context=None): diff --git a/trytond/tools/misc.py b/trytond/tools/misc.py index 24b9693798..bb99d87088 100644 --- a/trytond/tools/misc.py +++ b/trytond/tools/misc.py @@ -350,7 +350,7 @@ class Cache(object): kwargs.sort() # Work out key as a tuple of ('argname', value) pairs - key = (('dbname', cursor.dbname),) + tuple(kwargs) + key = (('dbname', cursor.dbname), str(kwargs)) # Check cache and return cached value if possible if key in self.cache: