From 124c3539aa37e449b52dc20c6325b2317afe32a4 Mon Sep 17 00:00:00 2001 From: fja-odoo Date: Fri, 13 Mar 2020 15:16:25 +0000 Subject: [PATCH] [FIX] website: perf - prefetch access token to avoid extra request Access_token has a restricted group, so it not fetched by defaut. In our case, we know that after the first access to partner_id, that will fill the cache without access_token, we will access access_token (so new query). So we access first the access_token, to have only one request that fill the cache with the access_token, and the partner_id used later. Related to #47257 task-2211013 X-original-commit: 7dd69d10d00d5f4a7c12ec414d63f868a10683be --- addons/website/models/website_visitor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/website/models/website_visitor.py b/addons/website/models/website_visitor.py index f942a83fc1f..c9f9d826c8d 100644 --- a/addons/website/models/website_visitor.py +++ b/addons/website/models/website_visitor.py @@ -172,6 +172,9 @@ class WebsiteVisitor(models.Model): access_token = request.httprequest.cookies.get('visitor_uuid') if access_token: visitor = Visitor.with_context(active_test=False).search([('access_token', '=', access_token)]) + # Prefetch access_token and other fields. Since access_token has a restricted group and we access + # a non restricted field (partner_id) first it is not fetched and will require an additional query to be retrieved. + visitor.access_token if not self.env.user._is_public(): partner_id = self.env.user.partner_id