aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorUģis Ozols <ugis.ozolss@gmail.com>2010-12-03 13:25:58 +0200
committerUģis Ozols <ugis.ozolss@gmail.com>2010-12-03 13:25:58 +0200
commit329f39a37d1316ca818f742b5407f5d6dc4ae258 (patch)
treec36eb00d7f4c60003865a830b2c6fe647dc26da8 /app
parentdeca138ec9054488233f100a22edd12acdeaaf58 (diff)
downloadrefinerycms-blog-329f39a37d1316ca818f742b5407f5d6dc4ae258.tar.gz
refinerycms-blog-329f39a37d1316ca818f742b5407f5d6dc4ae258.tar.bz2
refinerycms-blog-329f39a37d1316ca818f742b5407f5d6dc4ae258.zip
Optimised post_count method. See gist for benchmarks - https://gist.github.com/726844
Diffstat (limited to 'app')
-rw-r--r--app/models/blog_category.rb9
1 files changed, 1 insertions, 8 deletions
diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb
index 6d5e886..8ffe834 100644
--- a/app/models/blog_category.rb
+++ b/app/models/blog_category.rb
@@ -8,15 +8,8 @@ class BlogCategory < ActiveRecord::Base
has_friendly_id :title, :use_slug => true
- # this might be able to be optimised a little more
def post_count
- count = 0
-
- self.posts.each do |p|
- count += 1 if p.live?
- end
-
- count
+ posts.select(&:live?).count
end
end