caching comment counts

This commit is contained in:
shlok007 2016-12-29 03:17:33 -05:00 committed by Shlok Srivastava
parent 89840d0bab
commit 9c6286182e
5 changed files with 36 additions and 2 deletions

View 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

View file

@ -242,6 +242,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do
t.boolean "is_highlight", default: false
t.integer "program_id"
t.integer "max_attendees"
t.integer "comments_count", default: 0, null: false
end
create_table "events_registrations", force: :cascade do |t|