[IMP] http_routing: use cached code from lang
In case of short controller that don't use qweb template, we don't need anyhting else that this url code that don't change frequently. It make only sense for model like lang, website, ... that will not change frequently. And are called on each call by the dispatcher. In case of a website page, we will btw browse lang later, but in case of small controller like /favicon.ico, or page without qweb, ... we can just use the same from last query.
This commit is contained in:
committed by
Romain Derie
parent
a65d27cce9
commit
26c4de2f18
@@ -411,7 +411,7 @@ class IrHttp(models.AbstractModel):
|
||||
lang = preferred_lang or cls._get_default_lang()
|
||||
|
||||
request.lang = lang
|
||||
context['lang'] = lang.code
|
||||
context['lang'] = lang._get_cached('code')
|
||||
|
||||
# bind modified context
|
||||
request.context = context
|
||||
|
||||
@@ -95,7 +95,7 @@ class TestWebsitePerformance(UtilPerf):
|
||||
def test_30_perf_sql_queries_page_no_layout(self):
|
||||
# website.page with no call to layout templates
|
||||
self.page.arch = '<div>I am a blank page</div>'
|
||||
self.assertEqual(self._get_url_hot_query(self.page.url), 10)
|
||||
self.assertEqual(self._get_url_hot_query(self.page.url), 9)
|
||||
|
||||
def test_40_perf_sql_queries_page_multi_level_menu(self):
|
||||
# menu structure should not impact SQL requests
|
||||
|
||||
@@ -213,6 +213,19 @@ class Lang(models.Model):
|
||||
langs = self.with_context(active_test=False).search([])
|
||||
return sorted([(lang.code, lang.url_code, lang.name) for lang in langs], key=itemgetter(2))
|
||||
|
||||
@tools.ormcache('self.id')
|
||||
def _get_cached_values(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'id': self.id,
|
||||
'code': self.code,
|
||||
'url_code': self.url_code,
|
||||
'name': self.name,
|
||||
}
|
||||
|
||||
def _get_cached(self, field):
|
||||
return self._get_cached_values()[field]
|
||||
|
||||
@api.model
|
||||
@tools.ormcache('code')
|
||||
def _lang_code_to_urlcode(self, code):
|
||||
|
||||
Reference in New Issue
Block a user