summaryrefslogtreecommitdiff
path: root/addons/web/models
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-04-19 10:10:54 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-05-20 08:52:18 +0000
commit8a28cc22fd242f5fb59f23d1443ed8ed438249d7 (patch)
tree85b2df5a1f58f84ee5ef931aaa31d175e5646f0c /addons/web/models
parentd9b0b09bd2a9a359ff04d28fd1a6f5c06f89f378 (diff)
[IMP] base,web: Improve webclient startup
Today, some resources that varies very infrequentely are requested on every page load: the menus, the translations and the qweb templates After this commit, there will be 2 improvements that will make the loading of the webclient faster: 1. cache almost static resources forever when loading the /web/ page, the user session will contain the cache key to be used to fetch these resources. As the content of the resource itself it used to compute the hash, the request can be put in cache by the browser forever (for a year). The up side is that in general less requests are needed to load the web client The down side is that the load time and number of queries of /web page has increased to include what is needed to compute the hash of translations, menus and qweb templates 2. trigger the loading of the menus before the download (and startup) of the JS and CSS assets: The menus contains the definition of the action, wich is the first thing needed to load a page in odoo. Starting the loading of the menu much earlier means that when they are not yet in the browser cache (see point 1), the browser does not need to wait for the entire assets to be downloaded and parsed before starting the 'load_menu' request, but instead start it immediately and hold onto a promise to be used instead of the rpc 'load_menu'. Because the request is done before anything else is loaded, including JQuery, it is made in vanilla JS. Co-authored-by: Julien Mougenot <jum@odoo.com>
Diffstat (limited to 'addons/web/models')
-rw-r--r--addons/web/models/ir_http.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/addons/web/models/ir_http.py b/addons/web/models/ir_http.py
index 15fc49cff29..0253599d508 100644
--- a/addons/web/models/ir_http.py
+++ b/addons/web/models/ir_http.py
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
+import hashlib
import json
from odoo import models
from odoo.http import request
+from odoo.tools import ustr
+
+from odoo.addons.web.controllers.main import concat_xml, manifest_glob, module_boot
import odoo
@@ -21,6 +24,19 @@ class Http(models.AbstractModel):
def session_info(self):
user = request.env.user
version_info = odoo.service.common.exp_version()
+
+ user_context = request.session.get_context() if request.session.uid else {}
+
+ mods = ','.join(module_boot())
+ files = [f[0] for f in manifest_glob('qweb', addons=mods)]
+ _, qweb_checksum = concat_xml(files)
+
+ lang = user_context.get("lang")
+ translations_per_module, _ = request.env['ir.translation'].get_translations_for_webclient(mods, lang)
+
+ menu_json_utf8 = json.dumps(request.env['ir.ui.menu'].load_menus(request.debug), default=ustr, sort_keys=True).encode()
+ translations_json_utf8 = json.dumps(translations_per_module, sort_keys=True).encode()
+
return {
"uid": request.session.uid,
"is_system": user._is_system() if request.session.uid else False,
@@ -41,7 +57,11 @@ class Http(models.AbstractModel):
"show_effect": True,
"display_switch_company_menu": user.has_group('base.group_multi_company') and len(user.company_ids) > 1,
"toggle_company": user.has_group('base.group_toggle_company'),
-
+ "cache_hashes": {
+ "load_menus": hashlib.sha1(menu_json_utf8).hexdigest(),
+ "qweb": qweb_checksum,
+ "translations": hashlib.sha1(translations_json_utf8).hexdigest(),
+ },
}
def get_currencies(self):