Optimised post_count method. See gist for benchmarks - https://gist.github.com/726844

This commit is contained in:
Uģis Ozols 2010-12-03 13:25:58 +02:00
parent deca138ec9
commit 329f39a37d

View file

@ -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