diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-09-06 12:51:06 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-09-06 12:51:07 +0000 |
| commit | a5ef86754193af40b874f1d097ab50e096368f21 (patch) | |
| tree | 5eb6ec11c58b1900a8e725039cdea07056973692 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | 4903fb6290822bacad2d64328aa4b29747b25432 (diff) | |
[IMP] website_blog: prefetch the first post with the other posts
This reduces the number of queries by 4 on this route.
Here are the solutions that have been considered on how to share this prefetch.
[0].name
--------
Calling `(first_post | posts)[0].name` does not work because `[0]` is another
prefetch, it still does all the queries.
See `__getitem__` in `models.py`, `_prefetch_ids` is not forwarded, as opposed
to `__iter__`.
.mapped('name')
---------------
Calling `(first_post | posts).mapped('name')` reduces the number of queries by 2
(because it does an iteration = share prefetch, but this is CPU time for
nothing).
The problem is that even in that case, when computing the display name of a blog
for the slug (`slug(blog_post.blog_id)` or `slug(first_post.blog_id)`) if the
posts are on a different prefetch, the query will be done twice because their
m2o (blog_id in this case) will be on a different prefetch each.
.blog_id.mapped('name')
-----------------------
Calling `(first_post | posts).blog_id.mapped('name')`. would be the same as
using `with_prefetch` in this case, but it will be less robust. It is also
slightly more CPU to do the map for no reason, though it is really not a factor.
But the main problem is that it only works because we know `.blog_id.name` will
be accessed, but if the view is changed some day to access a field of another
m2o, this will not be optimized, while `with_prefetch` it is always guaranteed.
In conclusion the solution with `with_prefetch` was used because it is explicit,
more robust, and without any side effect.
Part of task-2061122
closes odoo/odoo#36507
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
0 files changed, 0 insertions, 0 deletions
