summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2020-03-13 15:16:35 +0000
committerRomain Derie <rde@odoo.com>2020-03-19 15:37:47 +0000
commitc2142a34f73cb8329e8d214596484bd9a581b3e6 (patch)
tree0da4bf1ac11a71c285a94ac3b20028ad380e6482 /addons
parente27eb978a6e4283510e4704fe574585e4ee27d64 (diff)
[FIX] website: perf - cache the compute hash for translation
Before this commit, we compute the hash on each request, to know if we need to download the file from the frontend or if we can use cache. Now we store the hash computed in cache. The cache will be invalidated when we touch one of these translations (openerp-web in the comments) or when you install a new lang (already the case). + avoid to use read on a record, since it will not use the cache from record. Related to #47257 task-2211013 X-original-commit: d5aaecbc51de19ef1d8d9988b691177fc73a4b86
Diffstat (limited to 'addons')
-rw-r--r--addons/http_routing/models/ir_http.py12
-rw-r--r--addons/web/models/ir_http.py11
2 files changed, 4 insertions, 19 deletions
diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py
index d4755f0b2b7..4f441b2079a 100644
--- a/addons/http_routing/models/ir_http.py
+++ b/addons/http_routing/models/ir_http.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-import hashlib
-import json
import logging
import os
import re
@@ -302,18 +300,12 @@ class IrHttp(models.AbstractModel):
modules = IrHttpModel.get_translation_frontend_modules()
user_context = request.session.get_context() if request.session.uid else {}
lang = user_context.get('lang')
- translations, lang_params = request.env['ir.translation'].get_translations_for_webclient(modules, lang)
- translation_cache = {
- 'lang_parameters': lang_params,
- 'modules': translations,
- 'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1,
- 'lang': lang,
- }
+ translation_hash = request.env['ir.translation'].get_web_translations_hash(modules, lang)
session_info.update({
'translationURL': '/website/translations',
'cache_hashes': {
- 'translations': hashlib.sha512(json.dumps(translation_cache, sort_keys=True).encode()).hexdigest()[:64], # sha512/256
+ 'translations': translation_hash,
},
})
return session_info
diff --git a/addons/web/models/ir_http.py b/addons/web/models/ir_http.py
index fd4e3bc923e..3c5839aa042 100644
--- a/addons/web/models/ir_http.py
+++ b/addons/web/models/ir_http.py
@@ -50,19 +50,12 @@ class Http(models.AbstractModel):
mods = module_boot()
qweb_checksum = HomeStaticTemplateHelpers.get_qweb_templates_checksum(addons=mods, debug=request.session.debug)
lang = user_context.get("lang")
- translations_per_module, lang_params = request.env['ir.translation'].get_translations_for_webclient(mods, lang)
- translation_cache = {
- 'lang': lang,
- 'lang_parameters': lang_params,
- 'modules': translations_per_module,
- 'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1,
- }
+ translation_hash = request.env['ir.translation'].get_web_translations_hash(mods, lang)
menu_json_utf8 = json.dumps(request.env['ir.ui.menu'].load_menus(request.session.debug), default=ustr, sort_keys=True).encode()
- translations_json_utf8 = json.dumps(translation_cache, sort_keys=True).encode()
cache_hashes = {
"load_menus": hashlib.sha512(menu_json_utf8).hexdigest()[:64], # sha512/256
"qweb": qweb_checksum,
- "translations": hashlib.sha512(translations_json_utf8).hexdigest()[:64], # sha512/256
+ "translations": translation_hash,
}
session_info.update({
# current_company should be default_company