优化院校评测同步

video_transcode
daiao 5 years ago
parent df3adb6542
commit 2d0ac4d765

@ -2,16 +2,18 @@ desc "同步学院或者单位评测数"
namespace :sync_evaluate do
task outpus_count: :environment do
School.find_each do |school|
puts school.id
evaluate_count = Game.find_by_sql("select sum(g.evaluate_count) as e_count from games g, user_extensions ue where
g.user_id = ue.user_id and ue.school_id = '#{school.id}'").first.try(:e_count)
School.find_in_batches(batch_size: 500) do |school|
Parallel.each_with_index(school, in_processes: 4) do |s|
puts "school_id:#{s.id}"
evaluate_count = Game.find_by_sql("select sum(g.evaluate_count) as e_count from games g, user_extensions ue where
g.user_id = ue.user_id and ue.school_id = '#{s.id}'").first.try(:e_count)
report = SchoolReport.find_or_initialize_by(school_id: school.id)
report.school_name = school.name
report.shixun_evaluate_count = evaluate_count
report = SchoolReport.find_or_initialize_by(school_id: s.id)
report.school_name = s.name
report.shixun_evaluate_count = evaluate_count
report.save
report.save
end
end
end
end
Loading…
Cancel
Save