From f6d56afba0ea96529b1419bf2ed4ac12fc5e98c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 13 Sep 2019 14:30:13 +0000 Subject: [PATCH] [IMP] http: rollback from checked_call only if necessary The rollback clears the cache, which lose all data that have been fetched before arriving in the route method. This lost cache includes some website data that was used during the dispatch and that will be used again in the route. By keeping it we reduce the number of queries on every request by at least 2. Part of task-2061122 closes odoo/odoo#36245 Signed-off-by: Raphael Collet (rco) --- odoo/http.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/http.py b/odoo/http.py index 90acbbe7cf7..cc26cd80a1f 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -331,14 +331,18 @@ class WebRequest(object): if self.endpoint.first_arg_is_req: args = (request,) + args + first_time = True + # Correct exception handling and concurency retry @service_model.check def checked_call(___dbname, *a, **kw): + nonlocal first_time # The decorator can call us more than once if there is an database error. In this # case, the request cursor is unusable. Rollback transaction to create a new one. - if self._cr: + if self._cr and not first_time: self._cr.rollback() self.env.clear() + first_time = False result = self.endpoint(*a, **kw) if isinstance(result, Response) and result.is_qweb: # Early rendering of lazy responses to benefit from @service_model.check protection