From c67936ec24ace1bb16b6a4604f1164f5065d78ac Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 26 Aug 2014 14:55:48 +0200 Subject: [PATCH] [IMP] refactor bundle ir.attachment cache invalidation --- openerp/addons/base/ir/ir_attachment.py | 8 ++++++++ openerp/addons/base/ir/ir_qweb.py | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/ir/ir_attachment.py b/openerp/addons/base/ir/ir_attachment.py index de768d23cc6..92c5a93f75c 100644 --- a/openerp/addons/base/ir/ir_attachment.py +++ b/openerp/addons/base/ir/ir_attachment.py @@ -330,4 +330,12 @@ class ir_attachment(osv.osv): return self.pool.get('ir.actions.act_window').for_xml_id( cr, uid, 'base', 'action_attachment', context=context) + def invalidate_bundle(self, cr, uid, type='%', xmlid=None, context=None): + assert type in ('%', 'css', 'js'), "Unhandled bundle type" + xmlid = '%' if xmlid is None else xmlid + '%' + domain = [('url', '=like', '/web/%s/%s/%%' % (type, xmlid))] + ids = self.search(cr, uid, domain, context=context) + if ids: + self.unlink(cr, uid, ids, context=context) + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index 8116ef61bfd..ca676f1b5d6 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -1153,12 +1153,8 @@ class AssetsBundle(object): def set_cache(self, type, content): ira = self.registry['ir.attachment'] - url_prefix = '/web/%s/%s/' % (type, self.xmlid) - # Invalidate previous caches - oids = ira.search(self.cr, self.uid, [('url', '=like', url_prefix + '%')], context=self.context) - if oids: - ira.unlink(self.cr, openerp.SUPERUSER_ID, oids, context=self.context) - url = url_prefix + self.version + ira.invalidate_bundle(self.cr, openerp.SUPERUSER_ID, type=type, xmlid=self.xmlid) + url = '/web/%s/%s/%s' % (type, self.xmlid, self.version) ira.create(self.cr, openerp.SUPERUSER_ID, dict( datas=content.encode('utf8').encode('base64'), type='binary',