Optimised post_count method. See gist for benchmarks - https://gist.github.com/726844
This commit is contained in:
parent
deca138ec9
commit
329f39a37d
1 changed files with 1 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue