优化数据迁移效率
This commit is contained in:
parent
259799eb89
commit
0a58fce251
|
@ -1,23 +1,27 @@
|
|||
class ChangeSeemsRateableRates < ActiveRecord::Migration
|
||||
def up
|
||||
SeemsRateableRates.where("rateable_type = 'HomeworkAttach'").each do |rate|
|
||||
homework = HomeworkAttach.find_by_id rate.rateable_id
|
||||
if homework
|
||||
course = homework.bid.courses.first
|
||||
if course
|
||||
teachers = []
|
||||
course.members.each do |m|
|
||||
teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course)
|
||||
end
|
||||
if teachers.include?(rate.rater_id)
|
||||
rate.is_teacher_score = 1
|
||||
rate.save
|
||||
Course.all.each do |course|
|
||||
teachers = []
|
||||
course.members.each do |m|
|
||||
teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course)
|
||||
end
|
||||
course.homeworks.each do |bid|
|
||||
bid.homeworks.each do |homework|
|
||||
SeemsRateableRates.where("rateable_type = 'HomeworkAttach' and rateable_id = #{homework.id}").each do |rate|
|
||||
if teachers.include?(rate.rater_id)
|
||||
rate.is_teacher_score = 1
|
||||
rate.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
SeemsRateableRates.where("is_teacher_score = 1").each do |rate|
|
||||
rate.is_teacher_score = 0
|
||||
rate.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue