优化数据迁移效率

This commit is contained in:
sw 2014-12-29 11:53:26 +08:00
parent 259799eb89
commit 0a58fce251
1 changed files with 17 additions and 13 deletions

View File

@ -1,14 +1,13 @@
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
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
@ -17,7 +16,12 @@ class ChangeSeemsRateableRates < ActiveRecord::Migration
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