summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoren Van Onder <jov@odoo.com>2019-08-28 01:30:46 +0000
committerJoren Van Onder <jov@odoo.com>2019-08-28 17:29:05 +0000
commit3a2eee5c8fc7fe58b5cdd21a43f16f0cd9269f38 (patch)
tree275748557da1a2f446b22089e94e9223f2b21ace
parent6d8e5efa84ddabd349068bbbaa7c25de14ce1dbc (diff)
[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>
-rw-r--r--addons/website_blog/controllers/main.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py
index 6f02268afc0..947ae83b06d 100644
--- a/addons/website_blog/controllers/main.py
+++ b/addons/website_blog/controllers/main.py
@@ -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)))