[IMP] website: avoid computing multi_website_ qcontext if not useful

Those values are only used on the website navbar when the user is in both groups
so the vast majority of the time they are done for no reason.

This reduces the number of queries by 2 on every page when the user is not admin
and/or multi website is not enabled.

Part of task-2061122

closes odoo/odoo#36483

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Sébastien Theys
2019-09-05 14:53:16 +00:00
parent 3cadfebf0f
commit c6bb103eac
+12 -11
View File
@@ -331,18 +331,19 @@ class View(models.Model):
qcontext['main_object'] = self
cur = Website.get_current_website()
qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur.domain}
qcontext['multi_website_websites'] = [
{'website_id': website.id, 'name': website.name, 'domain': website.domain}
for website in Website.search([]) if website != cur
]
if self.env.user.has_group('website.group_website_publisher') and self.env.user.has_group('website.group_multi_website'):
qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur.domain}
qcontext['multi_website_websites'] = [
{'website_id': website.id, 'name': website.name, 'domain': website.domain}
for website in Website.search([]) if website != cur
]
cur_company = self.env.user.company_id
qcontext['multi_website_companies_current'] = {'company_id': cur_company.id, 'name': cur_company.name}
qcontext['multi_website_companies'] = [
{'company_id': comp.id, 'name': comp.name}
for comp in self.env.user.company_ids if comp != cur_company
]
cur_company = self.env.user.company_id
qcontext['multi_website_companies_current'] = {'company_id': cur_company.id, 'name': cur_company.name}
qcontext['multi_website_companies'] = [
{'company_id': comp.id, 'name': comp.name}
for comp in self.env.user.company_ids if comp != cur_company
]
qcontext.update(dict(
self._context.copy(),