[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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user