From f2bd8122a8f200f590f1027705dfd83605460181 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 30 May 2019 17:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=89=8D=E4=BC=9A=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...530055732_add_evaluate_count_to_shixuns.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb b/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb index 9389afd0..7bd6dcd1 100644 --- a/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb +++ b/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb @@ -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