[IMP] base: make translations unique

With the unique constrain, the slow SELECT DISTINCT query can be removed

Fixes #18679
This commit is contained in:
Raphael Collet
2018-01-04 14:48:41 +01:00
committed by Martin Trigaux
parent d9436e34f8
commit 160d657704
2 changed files with 5 additions and 5 deletions
+2 -1
View File
@@ -261,7 +261,8 @@ class IrTranslation(models.Model):
res = super(IrTranslation, self)._auto_init()
# Add separate md5 index on src (no size limit on values, and good performance).
tools.create_index(self._cr, 'ir_translation_src_md5', self._table, ['md5(src)'])
tools.create_index(self._cr, 'ir_translation_ltn', self._table, ['name', 'lang', 'type'])
tools.create_unique_index(self._cr, 'ir_translation_unique', self._table,
['type', 'name', 'lang', 'res_id', 'md5(src)'])
return res
@api.model
+3 -4
View File
@@ -3541,16 +3541,15 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
# The parenthesis surrounding the select are important, as this is a sub-select.
# The quotes surrounding `ir_translation` are important as well.
unique_translation_subselect = """
(SELECT DISTINCT ON (res_id) res_id, value
FROM "ir_translation"
WHERE name=%s AND lang=%s AND value!=%s
(SELECT res_id, value FROM "ir_translation"
WHERE name=%s AND lang=%s AND value!=''
ORDER BY res_id, id DESC)
"""
alias, alias_statement = query.add_join(
(table_alias, unique_translation_subselect, 'id', 'res_id', field),
implicit=False,
outer=True,
extra_params=["%s,%s" % (self._name, field), self.env.lang, ""],
extra_params=["%s,%s" % (self._name, field), self.env.lang],
)
return 'COALESCE("%s"."%s", "%s"."%s")' % (alias, 'value', table_alias, field)
else: