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
|
has_friendly_id :title, :use_slug => true
|
||||||
|
|
||||||
# this might be able to be optimised a little more
|
|
||||||
def post_count
|
def post_count
|
||||||
count = 0
|
posts.select(&:live?).count
|
||||||
|
|
||||||
self.posts.each do |p|
|
|
||||||
count += 1 if p.live?
|
|
||||||
end
|
|
||||||
|
|
||||||
count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue