Skip to content

Commit

Permalink
[FIX] website: perf - translation - avoid query to find what we know
Browse files Browse the repository at this point in the history
Before this commit, each module override _get_translation_frontend_modules_domain
from ir.http to add its own translation in website if needed and that module
is not starting by website_. Updating the domain from the super() call.
Since we know in most of the case the name, it is useless to do a:
   select name from module where name = 'name1' or name = 'name2'...

Now we support a new override of _get_translation_frontend_modules_name that will
allow to add the known module name directly in the list instead to make a search.

In case nobody override _get_translation_frontend_modules_domain, we don't need to
make an extra rpc to find the module.

Related to odoo#47257
task-2211013
  • Loading branch information
JKE-be authored and rdeodoo committed Mar 13, 2020
1 parent 886c160 commit 8df6340
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
21 changes: 16 additions & 5 deletions addons/http_routing/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,28 @@ def get_frontend_session_info(self):
@api.model
def get_translation_frontend_modules(self):
Modules = request.env['ir.module.module'].sudo()
domain = self._get_translation_frontend_modules_domain()
return Modules.search(
expression.AND([domain, [('state', '=', 'installed')]])
).mapped('name')
extra_modules_domain = self._get_translation_frontend_modules_domain()
extra_modules_name = self._get_translation_frontend_modules_name()
if extra_modules_domain:
new = Modules.search(
expression.AND([extra_modules_domain, [('state', '=', 'installed')]])
).mapped('name')
extra_modules_name += new
return extra_modules_name

@classmethod
def _get_translation_frontend_modules_domain(cls):
""" Return a domain to list the domain adding web-translations and
dynamic resources that may be used frontend views
"""
return [('name', '=', 'web')]
return []

@classmethod
def _get_translation_frontend_modules_name(cls):
""" Return a list of module name where web-translations and
dynamic resources may be used in frontend views
"""
return ['web']

bots = "bot|crawl|slurp|spider|curl|wget|facebookexternalhit".split("|")

Expand Down
7 changes: 3 additions & 4 deletions addons/payment/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models
from odoo.osv import expression


class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

@classmethod
def _get_translation_frontend_modules_domain(cls):
domain = super(IrHttp, cls)._get_translation_frontend_modules_domain()
return expression.OR([domain, [('name', '=', 'payment')]])
def _get_translation_frontend_modules_name(cls):
mods = super(IrHttp, cls)._get_translation_frontend_modules_name()
return mods + ['payment']
7 changes: 3 additions & 4 deletions addons/portal/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models
from odoo.osv import expression


class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

@classmethod
def _get_translation_frontend_modules_domain(cls):
domain = super(IrHttp, cls)._get_translation_frontend_modules_domain()
return expression.OR([domain, [('name', '=', 'portal')]])
def _get_translation_frontend_modules_name(cls):
mods = super(IrHttp, cls)._get_translation_frontend_modules_name()
return mods + ['portal']
7 changes: 3 additions & 4 deletions addons/web_editor/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from odoo import models
from odoo.http import request
from odoo.osv import expression


class IrHttp(models.AbstractModel):
Expand All @@ -22,6 +21,6 @@ def _dispatch(cls):
return super(IrHttp, cls)._dispatch()

@classmethod
def _get_translation_frontend_modules_domain(cls):
domain = super(IrHttp, cls)._get_translation_frontend_modules_domain()
return expression.OR([domain, [('name', '=', 'web_editor')]])
def _get_translation_frontend_modules_name(cls):
mods = super(IrHttp, cls)._get_translation_frontend_modules_name()
return mods + ['web_editor']
9 changes: 5 additions & 4 deletions addons/website/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from odoo import registry, SUPERUSER_ID
from odoo.http import request
from odoo.tools.safe_eval import safe_eval
from odoo.osv.expression import FALSE_DOMAIN, OR
from odoo.osv.expression import FALSE_DOMAIN

from odoo.addons.http_routing.models.ir_http import ModelConverter, _guess_mimetype
from odoo.addons.portal.controllers.portal import _build_url_w_params
Expand Down Expand Up @@ -226,9 +226,10 @@ def _get_default_lang(cls):
return super(Http, cls)._get_default_lang()

@classmethod
def _get_translation_frontend_modules_domain(cls):
domain = super(Http, cls)._get_translation_frontend_modules_domain()
return OR([domain, [('name', 'ilike', 'website')]])
def _get_translation_frontend_modules_name(cls):
mods = super(Http, cls)._get_translation_frontend_modules_name()
installed = request.registry._init_modules | set(odoo.conf.server_wide_modules)
return mods + [mod for mod in installed if mod.startswith('website')]

@classmethod
def _serve_page(cls):
Expand Down
9 changes: 4 additions & 5 deletions addons/website_livechat/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models
from odoo.osv import expression
from odoo import models


class IrHttp(models.AbstractModel):
_inherit = 'ir.http'

@classmethod
def _get_translation_frontend_modules_domain(cls):
domain = super(IrHttp, cls)._get_translation_frontend_modules_domain()
return expression.OR([domain, [('name', '=', 'im_livechat')]])
def _get_translation_frontend_modules_name(cls):
mods = super(IrHttp, cls)._get_translation_frontend_modules_name()
return mods + ['im_livechat']

0 comments on commit 8df6340

Please sign in to comment.