实训作业的关卡设置加唯一索引

dev_course
cxt 6 years ago
parent 7d8af1c407
commit 28c48c996e

@ -530,7 +530,7 @@ class HomeworkCommonsController < ApplicationController
if setting && setting.score != score
score_change = true
setting.update_attributes(score: score)
else
elsif setting.blank?
score_change = true
HomeworkChallengeSetting.create!(homework_common_id: @homework.id, challenge_id: challenge[:challenge_id],
shixun_id: @homework.homework_commons_shixun.try(:shixun_id), score: score)

@ -165,7 +165,7 @@ class HomeworksService
homework = work.homework_common
#logger.info("#############member_course_group_id: #{member.try(:course_group_id)}")
setting_time = homework.homework_group_setting work.user_id
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && !homework.course.is_end))
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && homework.late_time && homework.late_time > Time.now))
#logger.info("#############setting_time: #{setting_time.end_time}")
user_total_score = 0

@ -0,0 +1,10 @@
class AddUniqIndexToHomeworkChallengeSettings < ActiveRecord::Migration[5.2]
def change
remove_index :homework_challenge_settings, [:homework_common_id, :challenge_id] if index_exists?(:homework_challenge_settings, [:homework_common_id, :challenge_id])
sql = %Q(delete from homework_challenge_settings where (homework_common_id, challenge_id) in
(select * from (select homework_common_id, challenge_id from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1) a)
and id not in (select * from (select max(id) from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :homework_challenge_settings, [:homework_common_id, :challenge_id], unique: true, name: "index_on_homework_common_id_challenge_id"
end
end
Loading…
Cancel
Save