[IMP] website: don't query website table when serving homepage
We can easily avoid a read on the website table when serving the homepage by simply caching the website.homepage_id value and then browsing the record (no query needed) instead of reading it on the website record. While this code is not really elegant, it seems like a good tradeoff to gain a query on this particular homepage serve controller, which is the main entry point of a website and generally the page the more often served. task-2774979 X-original-commit: 69b443b85656c895c66a1f83b235f5d1e53727d4 Part-of: odoo/odoo#85456
This commit is contained in:
@@ -73,7 +73,8 @@ class Website(Home):
|
||||
# prefetch all menus (it will prefetch website.page too)
|
||||
top_menu = request.website.menu_id
|
||||
|
||||
homepage = request.website.homepage_id
|
||||
homepage_id = request.website._get_cached('homepage_id')
|
||||
homepage = homepage_id and request.env['website.page'].browse(homepage_id)
|
||||
if homepage and (homepage.sudo().is_visible or request.env.user.has_group('base.group_user')) and homepage.url != '/':
|
||||
return request.env['ir.http'].reroute(homepage.url)
|
||||
|
||||
|
||||
@@ -1350,6 +1350,7 @@ class Website(models.Model):
|
||||
'user_id': self.user_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
'default_lang_id': self.default_lang_id.id,
|
||||
'homepage_id': self.homepage_id.id,
|
||||
}
|
||||
|
||||
def _get_cached(self, field):
|
||||
|
||||
@@ -109,7 +109,7 @@ class TestWebsitePerformance(UtilPerf):
|
||||
|
||||
def test_20_perf_sql_queries_homepage(self):
|
||||
# homepage "/" has its own controller
|
||||
self.assertEqual(self._get_url_hot_query('/'), 13)
|
||||
self.assertEqual(self._get_url_hot_query('/'), 12)
|
||||
self.assertEqual(self._get_url_hot_query('/', cache=False), 15)
|
||||
|
||||
def test_30_perf_sql_queries_page_no_layout(self):
|
||||
|
||||
Reference in New Issue
Block a user