注释前会议

pre_develop
jingquan huang 6 years ago
parent b3ffa73ed1
commit f2bd8122a8

@ -2,20 +2,20 @@ class AddEvaluateCountToShixuns < ActiveRecord::Migration
def up
add_column :shixuns, :evaluate_count, :integer, default: 0
limit = 100
total = Shixun.count
((total / 100) + 1).times do |index|
shixun_ids = Shixun.order(:id).limit(limit).offset(index * limit).pluck(:id)
return if shixun_ids.blank?
count_map = Game.joins(:challenge).where(challenges: { shixun_id: shixun_ids }).group('shixun_id').sum(:evaluate_count)
id_str = count_map.keys.join(',')
str = count_map.map { |shixun_id, count| "WHEN #{shixun_id} THEN #{count}" }.join(' ')
execute "UPDATE shixuns SET evaluate_count = CASE id #{str} END WHERE id IN (#{id_str})"
end
# limit = 100
# total = Shixun.count
#
# ((total / 100) + 1).times do |index|
# shixun_ids = Shixun.order(:id).limit(limit).offset(index * limit).pluck(:id)
# return if shixun_ids.blank?
#
# count_map = Game.joins(:challenge).where(challenges: { shixun_id: shixun_ids }).group('shixun_id').sum(:evaluate_count)
#
# id_str = count_map.keys.join(',')
# str = count_map.map { |shixun_id, count| "WHEN #{shixun_id} THEN #{count}" }.join(' ')
#
# execute "UPDATE shixuns SET evaluate_count = CASE id #{str} END WHERE id IN (#{id_str})"
# end
end
def down

Loading…
Cancel
Save