[FIX] project: speed up name_search of tags on a task
Description:
The pop-up that shows suggestions when adding a tag on a task is
really slow (300~500ms per request on prod).
Cause:
`project.tag` has an override of `_name_search()`, which adds a
domain of the form
```python
['|', ('task_ids.project_id', '=', project_id),
('project_ids', 'in', project_id)]
```
which is expensive to compute.
Functional requirements:
- Suggest tags of the "project" first (those that are on tasks in the
same project), then all the rest.
- Tag's name should be sorted alphabetically per result set (tags on tasks of
project first, sorted alphabetically, then all other tags, sorted
alphabetically)
Solution:
Construct a custom query that makes use of CTE and `UNION ALL` to sort
only on a subsets of the tags to speed up. Also `UNION ALL` with a
`LIMIT` is lazy evaluated, so we gain on speed of all tags are comming
from tags on tasks in the current project.
Affected version:
- 16.0
- saas-16.1
- master
perf-3209468
closes odoo/odoo#114318
Signed-off-by:
Xavier Bol (xbo) <xbo@odoo.com>
Loading