From c44a42561d856d19c2c84460ae7c5e3c0f079c77 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 12 Jul 2013 12:35:12 -0300 Subject: [PATCH] Fixing performance issue with full blog view --- app/models/blog.rb | 4 ++++ app/views/search/_full_blog.html.erb | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/blog.rb b/app/models/blog.rb index 71e0501..7092d96 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -81,4 +81,8 @@ class Blog < Folder posts.empty? end + def last_posts(limit=3) + posts.where("type != 'RssFeed'").order(:updated_at).limit(limit) + end + end diff --git a/app/views/search/_full_blog.html.erb b/app/views/search/_full_blog.html.erb index e96a519..1cbdea1 100644 --- a/app/views/search/_full_blog.html.erb +++ b/app/views/search/_full_blog.html.erb @@ -7,12 +7,12 @@ <%= _("Last posts") %> - <% r = blog.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %> - "> - <% r.each do |a| %> - <%= link_to a.title, a.view_url, :class => 'search-blog-sample-item '+icon_for_article(a) %> + <% last_posts = blog.last_posts %> + "> + <% last_posts.each do |post| %> + <%= link_to post.title, post.view_url, :class => 'search-blog-sample-item '+icon_for_article(post) %> <% end %> - <%= _('None') if r.empty? %> + <%= _('None') if last_posts.empty? %> -- libgit2 0.21.2