pre_develop
hjm 6 years ago
commit 9273415055

@ -533,7 +533,7 @@ class GamesService
# 更新评测次数
game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1))
shixun.increment!(:evaluate_count)
# shixun.increment!(:evaluate_count)
# 清空代码评测信息
msg = game.run_code_message
msg.update_attributes(:status => 0, :message => nil) if msg.present?
@ -694,7 +694,7 @@ class GamesService
:evaluate_count]).find_by_identifier(params[:identifier])
# 更新评测次数
game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1))
game.challenge.shixun.increment!(:evaluate_count)
# game.challenge.shixun.increment!(:evaluate_count)
# 选择题如果通关了,则不让再评测
if game.status == 2

@ -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