[IMP] ir.qweb: cache assets and check content every 3 min
Don't use cache if the xml dev_mode is active
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user