Fixes #1230. Makes comment counter more efficient

This commit is contained in:
Emanuel Hayford 2017-03-16 06:41:15 +01:00
parent c5e3d495bb
commit 33df0ee8e4
5 changed files with 21 additions and 3 deletions

View 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

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170213145807) do
ActiveRecord::Schema.define(version: 20170316042351) do
create_table "ahoy_events", force: :cascade do |t|
t.uuid "visit_id", limit: 16
@ -234,6 +234,7 @@ ActiveRecord::Schema.define(version: 20170213145807) do
t.boolean "is_highlight", default: false
t.integer "program_id"
t.integer "max_attendees"
t.integer "comments_count", default: 0
end
create_table "events_registrations", force: :cascade do |t|