-
- Downloads
[IMP] base: don't prefetch translate field by default
Issue
-----
Via the field prefetch mechanism, when we need a value of one field
(not in cache of course), the ORM will prefetch all fields
(which has the attribute to `prefetch=True`, the default value of this
attribute is `True`) for all record ids in `_prefetch_ids`.
Then, for each translate fields (where translate is not a callable)
the ORM need to make a `LEFT JOIN` on the `ir_translation` to fetch the
translated value. For big model, it leads to a simple `SELECT` with
several `LEFT JOIN` on ir_translation but each LEFT JOIN have a cost
in the planner time (a small cost in the execution time) of PostgreSQL.
By example, for `product.template` (stock/sale/purchase installed),
there are 6 LEFT JOIN to get all translated fields (5 of this
fields are rarely used).
Proposed solution
-----------------
Deactivate the prefetch by default for all translate fields expect if
this field is the `_rec_name` of the model (which is more likely to
be used).
In the example on the `product.template`:
Without prefetching the translated fields, there is only one LEFT JOIN
(the name, which is translated but is the `_rec_name` of the model).
With the 6 translated fields to fetch, the
query takes 5 ms to plan and 2 ms to execute VS with 1 translate field,
it 1 ms to plan and 1.5 ms to execute.
Side change note
----------------
- All translate of fields of `website.seo.metadata` should be prefetch
to avoid lot of website errors (it is because, website put in cache data
in sudo before reading it without sudo)
- `description` (`mail.message.subtype`), `subject` (`mail.template`),
`body_html` (`mail.template`) should be prefetch to avoid lot of extra
query from mail module.
- `vat_label` (`res.country`) should be prefetch to avoid a extra query
for each website page.
- Increase some queryCount (when it is legit, due to `subtitle` of
`blog_post` or `description` of `event.type.ticket`, etc)
task-2738029
closes odoo/odoo#82896
Signed-off-by:
Raphael Collet <rco@odoo.com>
Showing
- addons/event/models/event_stage.py 3 additions, 3 deletionsaddons/event/models/event_stage.py
- addons/hr_work_entry_holidays/tests/test_performance.py 2 additions, 2 deletionsaddons/hr_work_entry_holidays/tests/test_performance.py
- addons/mail/models/mail_message_subtype.py 1 addition, 1 deletionaddons/mail/models/mail_message_subtype.py
- addons/mail/models/mail_template.py 3 additions, 3 deletionsaddons/mail/models/mail_template.py
- addons/sale_stock/tests/test_create_perf.py 4 additions, 4 deletionsaddons/sale_stock/tests/test_create_perf.py
- addons/test_event_full/tests/test_performance.py 3 additions, 3 deletionsaddons/test_event_full/tests/test_performance.py
- addons/website/models/mixins.py 4 additions, 4 deletionsaddons/website/models/mixins.py
- addons/website_blog/tests/test_performance.py 3 additions, 3 deletionsaddons/website_blog/tests/test_performance.py
- odoo/addons/base/models/res_country.py 1 addition, 1 deletionodoo/addons/base/models/res_country.py
- odoo/addons/base/tests/test_expression.py 2 additions, 1 deletionodoo/addons/base/tests/test_expression.py
- odoo/addons/test_new_api/models/test_new_api.py 11 additions, 0 deletionsodoo/addons/test_new_api/models/test_new_api.py
- odoo/addons/test_new_api/security/ir.model.access.csv 1 addition, 0 deletionsodoo/addons/test_new_api/security/ir.model.access.csv
- odoo/addons/test_new_api/tests/test_new_fields.py 14 additions, 0 deletionsodoo/addons/test_new_api/tests/test_new_fields.py
- odoo/fields.py 10 additions, 4 deletionsodoo/fields.py
Loading
Please register or sign in to comment