Fixes #1230. Makes comment counter more efficient
This commit is contained in:
parent
c5e3d495bb
commit
33df0ee8e4
5 changed files with 21 additions and 3 deletions
15
db/migrate/20170316042351_add_comment_count_to_events.rb
Normal file
15
db/migrate/20170316042351_add_comment_count_to_events.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class AddCommentCountToEvents < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :events, :comments_count, :integer, default: 0
|
||||
|
||||
Event.reset_column_information
|
||||
|
||||
Event.find_each do |event|
|
||||
event.update_attribute :comments_count, event.comment_threads.length
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :events, :comments_count
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue