diff options
| author | Romain Derie <rde@odoo.com> | 2020-03-26 18:06:32 +0000 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2020-03-26 18:12:47 +0000 |
| commit | 2c09e00a64a6f565d56c16c0b72549bc6c680b6a (patch) | |
| tree | cbf257113fdf235f342c058698b648937d38f1e9 /addons/website/controllers | |
| parent | 7ec403a1e3899a8dafae1dfc8ad623fcf8cad79f (diff) | |
[IMP] website: perf - prefetch menus when serving a page
If we are rendering a page, the menus will most likely be rendered as well.
Note that even in a 403 case when the page is found but is not visible, the
menus will also be shown on the 403 page.
Fetching the menus before accessing the requested page will prefetch that page
as well in one go if that page is in the menus, without any costs for the pages
not in the menus.
There is a tradeoff for 'non-layout' pages, which only occurs in advanced
technical cases:
1. Create a page with specific extension as name suffix (page.css) in which
case the page will be bootstraped accordingly, without call to layout.
2. Remove the call to layout in HTML editor or backend
3. Remove the call to submenus template in HTML editor or backend
For those cases, the menus will be prefetched for no reason.
Note that homepage '/' is rendered through a controller, same logic is applied
there.
task-2211013
Diffstat (limited to 'addons/website/controllers')
| -rw-r--r-- | addons/website/controllers/main.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 8019abba5c4..df2bf628660 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -68,6 +68,9 @@ class Website(Home): @http.route('/', type='http', auth="public", website=True, sitemap=True) def index(self, **kw): + # prefetch all menus (it will prefetch website.page too) + top_menu = request.website.menu_id + homepage = request.website.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) @@ -76,7 +79,6 @@ class Website(Home): if website_page: return website_page else: - top_menu = request.website.menu_id first_menu = top_menu and top_menu.child_id and top_menu.child_id.filtered(lambda menu: menu.is_visible) if first_menu and first_menu[0].url not in ('/', '', '#') and (not (first_menu[0].url.startswith(('/?', '/#', ' ')))): return request.redirect(first_menu[0].url) |
