diff options
author | Uģis Ozols <ugis.ozolss@gmail.com> | 2010-12-03 13:25:58 +0200 |
---|---|---|
committer | Uģis Ozols <ugis.ozolss@gmail.com> | 2010-12-03 13:25:58 +0200 |
commit | 329f39a37d1316ca818f742b5407f5d6dc4ae258 (patch) | |
tree | c36eb00d7f4c60003865a830b2c6fe647dc26da8 /app | |
parent | deca138ec9054488233f100a22edd12acdeaaf58 (diff) | |
download | refinerycms-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.rb | 9 |
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 |