[FIX] base: generate field translations based on index key

The ir_translation table has an index on the (name, lang, type and value)
key, however this index was not being used when generating field
translations because the column `type` was missing!

With this commit, we fully utilize the index when generating field
translations.

With the eCommerce with categories and 4k+ products, the time to charge
products per category would be around 4-5s; With this patch it is
reduced to 1-2s.

opw-1961665

closes odoo/odoo#33504

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Adrian Torres
2019-05-20 13:42:17 +00:00
parent 3c305daded
commit 09af3fac39
+1 -2
View File
@@ -3961,8 +3961,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
# The quotes surrounding `ir_translation` are important as well.
unique_translation_subselect = """
(SELECT res_id, value FROM "ir_translation"
WHERE name=%s AND lang=%s AND value!=''
ORDER BY res_id, id DESC)
WHERE type='model' AND name=%s AND lang=%s AND value!='')
"""
alias, alias_statement = query.add_join(
(table_alias, unique_translation_subselect, 'id', 'res_id', field),