From f586f9441e79f2c3e68ea0748359c14696f28d90 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 25 May 2016 11:30:24 +0200 Subject: [PATCH] [IMP] ir.qweb: cache assets and check content every 3 min Don't use cache if the xml dev_mode is active --- openerp/addons/base/ir/ir_qweb/ir_qweb.py | 7 ++++++- .../addons/test_assetsbundle/tests/test_assetsbundle.py | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/ir/ir_qweb/ir_qweb.py b/openerp/addons/base/ir/ir_qweb/ir_qweb.py index 1507c585d35..5008de0eb7b 100644 --- a/openerp/addons/base/ir/ir_qweb/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb/ir_qweb.py @@ -13,6 +13,7 @@ from openerp.tools import safe_eval from openerp.addons.web.http import request from odoo.modules.module import get_resource_path import json +from time import time import logging _logger = logging.getLogger(__name__) @@ -51,7 +52,7 @@ class ir_QWeb(models.AbstractModel, QWeb): """ attributes add to the values for each computed template """ default = super(ir_QWeb, self).default_values() - default.update(request=request) + default.update(request=request, cache_assets=round(time()/180)) return default # assume cache will be invalidated by third party on write to ir.ui.view @@ -137,6 +138,10 @@ class ir_QWeb(models.AbstractModel, QWeb): # method called by computing code + @tools.conditional( + 'xml' not in tools.config['dev_mode'], + tools.ormcache('xmlid', 'options.get("lang", "en_US")', 'css', 'js', 'debug', 'async', 'values.get("time_cache_assets")'), + ) def _get_asset(self, xmlid, options, css=True, js=True, debug=False, async=False, values=None): files, remains = self._get_asset_content(xmlid, options) asset = AssetsBundle(xmlid, files, remains, env=self.env) diff --git a/openerp/addons/test_assetsbundle/tests/test_assetsbundle.py b/openerp/addons/test_assetsbundle/tests/test_assetsbundle.py index ac98fd601b8..f4e95368b15 100644 --- a/openerp/addons/test_assetsbundle/tests/test_assetsbundle.py +++ b/openerp/addons/test_assetsbundle/tests/test_assetsbundle.py @@ -5,6 +5,7 @@ from openerp import api from openerp.tests import HttpCase from openerp.tests.common import TransactionCase from openerp.modules.module import get_resource_path +from openerp.addons.base.ir.ir_qweb import AssetsBundle from collections import Counter from os import utime @@ -18,7 +19,9 @@ class TestJavascriptAssetsBundle(TransactionCase): self.cssbundle_xmlid = 'test_assetsbundle.bundle2' def _get_asset(self, xmlid, env=None): - return (env or self.env)['ir.qweb']._get_asset(xmlid, {}) + env = (env or self.env) + files, remains = env['ir.qweb']._get_asset_content(xmlid, {}) + return AssetsBundle(xmlid, files, remains, env=env) def _any_ira_for_bundle(self, type): """ Returns all ir.attachments associated to a bundle, regardless of the verion. @@ -347,7 +350,9 @@ class TestAssetsBundleWithIRAMock(TransactionCase): def _bundle(self, should_create, should_unlink): self.counter.clear() - self.env['ir.qweb']._get_asset(self.lessbundle_xmlid, {}).to_html(debug='assets') + files, remains = self.env['ir.qweb']._get_asset_content(self.lessbundle_xmlid, {}) + asset = AssetsBundle(self.lessbundle_xmlid, files, remains, env=self.env) + asset.to_html(debug='assets') self.assertEquals(self.counter['create'], int(should_create)) self.assertEquals(self.counter['unlink'], int(should_unlink))