Skip to content
Permalink
Browse files

[IMP] website: cache the public_user_id on the website

In most cases, for a website page you will need to browse the website btw so
we don't remove this request previously. But in case of a simple image, the
controller /web/content need the public user just to set the request.uid in
auth_public but no other info from website.

With this commit, we don't do the 'select * from website where id in()'
request on each controller declared in auth='public' but use the user_id
from the cache. (Invalidated by the write on website_id)
  • Loading branch information
JKE-be authored and rdeodoo committed Mar 24, 2020
1 parent d060dc9 commit 87bdef79a06616750d21bfb15f55a2a5c6a6b520
Showing with 10 additions and 5 deletions.
  1. +3 −3 addons/website/models/ir_http.py
  2. +5 −0 addons/website/models/website.py
  3. +2 −2 addons/website/tests/test_performance.py
@@ -13,7 +13,7 @@
from functools import partial

import odoo
from odoo import api, models
from odoo import api, models, tools
from odoo import registry, SUPERUSER_ID
from odoo.http import request
from odoo.tools.safe_eval import safe_eval
@@ -132,8 +132,8 @@ def _auth_method_public(cls):
if not request.session.uid:
env = api.Environment(request.cr, SUPERUSER_ID, request.context)
website = env['website'].get_current_website()
if website and website.user_id:
request.uid = website.user_id.id
request.uid = website and website._get_public_user_id()

if not request.uid:
super(Http, cls)._auth_method_public()

@@ -949,6 +949,11 @@ def _is_canonical_url(self, canonical_params):
# if the current URL is indeed canonical or not.
return current_url == canonical_url

@tools.ormcache('self.id')
@api.model
def _get_public_user_id(self):
return self.user_id.id


class BaseModel(models.AbstractModel):
_inherit = 'base'
@@ -38,7 +38,7 @@ def test_10_perf_sql_img_controller(self):

def test_20_perf_sql_img_controller_bis(self):
url = '/web/image/website/1/favicon'
self.assertEqual(self._get_url_hot_query(url), 5)
self.assertEqual(self._get_url_hot_query(url), 4)
self.authenticate('portal', 'portal')
self.assertEqual(self._get_url_hot_query(url), 4)

@@ -121,4 +121,4 @@ def test_50_perf_sql_web_content(self):
# assets route /web/content/..
self.url_open('/') # create assets attachments
assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/content/%/web.assets_common%.js')], limit=1).url
self.assertEqual(self._get_url_hot_query(assets_url), 4)
self.assertEqual(self._get_url_hot_query(assets_url), 3)

0 comments on commit 87bdef7

Please sign in to comment.
You can’t perform that action at this time.