caching comment counts
This commit is contained in:
parent
89840d0bab
commit
9c6286182e
5 changed files with 36 additions and 2 deletions
10
db/migrate/20161229080315_add_comments_count_to_events.rb
Normal file
10
db/migrate/20161229080315_add_comments_count_to_events.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class AddCommentsCountToEvents < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :events, :comments_count, :integer, default: 0, null: false
|
||||
|
||||
Event.find_each do |event|
|
||||
comments_count = event.comment_threads.count
|
||||
event.update_attribute(:comments_count, comments_count) unless comments_count.zero?
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue