[FIX] website_blog: speed up loading blog posts when there are many

Doing filtered on all_post is problematic in case there are many
blog.post records (>5000 were observed). It will trigger prefetching
which will run the content fields through html_translate which can
take many seconds to complete.

Instead replace the filtered call with a more precise search domain.

opw-2060704, opw-2060706

closes odoo/odoo#36207

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Joren Van Onder
2019-08-28 17:29:05 +00:00
parent 6d8e5efa84
commit 3a2eee5c8f
+4 -2
View File
@@ -238,9 +238,11 @@ class WebsiteBlog(http.Controller):
tags = request.env['blog.tag'].search([])
# Find next Post
all_post = BlogPost.search([('blog_id', '=', blog.id)])
blog_post_domain = [('blog_id', '=', blog.id)]
if not request.env.user.has_group('website.group_website_designer'):
all_post = all_post.filtered(lambda r: r.post_date <= fields.Datetime.now())
blog_post_domain += [('post_date', '<=', fields.Datetime.now())]
all_post = BlogPost.search(blog_post_domain)
if blog_post not in all_post:
return request.redirect("/blog/%s" % (slug(blog_post.blog_id)))