Add cache and md5 on fields_view_get

This commit is contained in:
ced@b2ck.com
2007-12-27 23:42:01 +01:00
parent a9ca07a7c2
commit 9de087a238
3 changed files with 49 additions and 2 deletions
+40
View File
@@ -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()
+8 -1
View File
@@ -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):
+1 -1
View File
@@ -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: