diff options
| author | Denis Ledoux <dle@odoo.com> | 2016-01-12 15:17:32 +0100 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2016-01-12 17:40:58 +0100 |
| commit | 6a366b216b3d119cd5546c877a2f77b5342cb452 (patch) | |
| tree | 8af4513be85fc122e2bc306b3ff16a3a917cbadb /addons/mail/static/src/xml/thread.xml | |
| parent | 1676f66ad37fa318d21b321b9f41b426a8dc0830 (diff) | |
[FIX] models: order by translatable fields with multiple translations
When a model list is ordered on a translatable field,
a join on the `ir_translation` is done, so the order
is correctly done on the translation value rather
than the translation source (in English).
This join wasn't entirely correct: If there were
multiple translations for a same record field
(which should not happen, but which is not forbidden)
e.g. Two different translations for the name of a same product,
then this record appeared several times in the result of the query,
while this is expected to only have each record once
(Obviously, when you perform a search on products, you do not expect
to have multiple times the same products returned by the search query)
This had as side-effect, when searching records with a limit of 80
items, to return actually less than 80 items
(e.g. 72 products, with multiple translations),
and, as the limit of the search was not reached (e.g. 72 instead of 80),
the web client did not perform the `search_count`, as it does not do
it when the limit of the search is not reached (meaning there is no
more items than what has been returned by the search query), and therefore
the web client did not consider there was actually more results, more
pages of results.
In summary, the count of records of a model could be different
when performing the order on a translatable field from one
language to another.
(e.g. A database could return 150 products in English, but
only 72 in Spanish).
To solve this issue, we have required the use of the operator
`DISTINCT ON`, which provides the possibility to keep only
the first translation for each record according to a given
order (in this case, we keep the translation that has been
added the most recently)
From the PostgreSQL documentation:
DISTINCT ON ( expression [, ...] ) keeps only the first row
of each set of rows where the given expressions evaluate to equal.
The DISTINCT ON expressions are interpreted
using the same rules as for ORDER BY (see above).
Note that the "first row" of each set is unpredictable
unless ORDER BY is used to ensure that the desired row appears first
The performance of this new query is similar to the performance
of the former query.
opw-666071
Diffstat (limited to 'addons/mail/static/src/xml/thread.xml')
0 files changed, 0 insertions, 0 deletions
