Sébastien Theys a5ef867541 [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>
2019-09-06 12:51:07 +00:00
…
2018-10-09 13:44:38 +00:00
…
…
…

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, Purchase Management, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

Then follow the developer tutorials

S
Description
No description provided
Readme LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%