From 0d1d225249ce79f900ed191e206045207bb6ac62 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 26 Jun 2014 18:18:12 +0200 Subject: [PATCH] Remove ir.ui.view last_update collection and use checksum on rendered bundle --- openerp/addons/base/ir/ir_qweb.py | 36 ++++++++++------------------ openerp/addons/base/ir/ir_ui_view.py | 15 +++--------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index d69535c8576..943675a3ebb 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -1028,26 +1028,14 @@ class AssetsBundle(object): self.css_errors = [] self.remains = [] self._checksum = None - self._last_modified = datetime.datetime(1970, 1, 1) - last_updates = [] context = self.context.copy() - context.update( - inherit_branding=False, - collect_last_updates=last_updates, - ) - html = self.registry['ir.ui.view'].render(self.cr, self.uid, xmlid, context=context) - if last_updates: - # ir.ui.view are orm cached. If the bundle view is actually cached, we won't receive - # last_updates. In this case we consider it's already cached in self.cache and thus - # only the dates of the files/ir.attachements assets will be compared. - server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT - self._last_modified = datetime.datetime.strptime(max(last_updates), server_format) - if html: - self.parse(html) + context['inherit_branding'] = False + self.html = self.registry['ir.ui.view'].render(self.cr, self.uid, xmlid, context=context) + self.parse() - def parse(self, html): - fragments = lxml.html.fragments_fromstring(html) + def parse(self): + fragments = lxml.html.fragments_fromstring(self.html) for el in fragments: if isinstance(el, basestring): self.remains.append(el) @@ -1102,22 +1090,24 @@ class AssetsBundle(object): @lazy_property def last_modified(self): + """Returns last modified date of linked files""" return max(itertools.chain( (asset.last_modified for asset in self.javascripts), (asset.last_modified for asset in self.stylesheets), - [self._last_modified], )) @lazy_property def version(self): - return hashlib.sha1(str(self.last_modified)).hexdigest()[0:7] + return self.checksum[0:7] @lazy_property def checksum(self): - checksum = hashlib.new('sha1') - for asset in itertools.chain(self.javascripts, self.stylesheets): - checksum.update(asset.content.encode("utf-8")) - return checksum.hexdigest() + """ + Not really a full checksum. + We compute a SHA1 on the rendered bundle + max linked files last_modified date + """ + check = self.html + str(self.last_modified) + return hashlib.sha1(check).hexdigest() def js(self): key = 'js_%s' % self.xmlid diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index b6fed6ddfbd..5ca4b26b046 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -367,13 +367,9 @@ class view(osv.osv): ]) view_ids = self.search(cr, uid, conditions, context=context) - inheriting_views = [] - for view in self.browse(cr, 1, view_ids, context): - if not (view.groups_id and user_groups.isdisjoint(view.groups_id)): - inheriting_views.append((view.arch, view.id)) - if 'collect_last_updates' in context: - context['collect_last_updates'].append(view.write_date) - return inheriting_views + return [(view.arch, view.id) + for view in self.browse(cr, 1, view_ids, context) + if not (view.groups_id and user_groups.isdisjoint(view.groups_id))] def raise_view_error(self, cr, uid, message, view_id, context=None): view = self.browse(cr, uid, view_id, context) @@ -550,18 +546,13 @@ class view(osv.osv): v = v.inherit_id root_id = v.id - collect_last_updates = 'collect_last_updates' in context # arch and model fields are always returned if fields: fields = list(set(fields) | set(['arch', 'model'])) - if collect_last_updates and 'write_date' not in fields: - fields.append('write_date') # read the view arch [view] = self.read(cr, uid, [root_id], fields=fields, context=context) view_arch = etree.fromstring(view['arch'].encode('utf-8')) - if collect_last_updates: - context['collect_last_updates'].append(view['write_date']) if not v.inherit_id: arch_tree = view_arch else: