|
|
|
@ -10,7 +10,7 @@ namespace :subjects do
|
|
|
|
|
subjects.find_in_batches(batch_size: 50) do |s|
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
Parallel.each(s, in_processes: 4) do |subject|
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 4) do |subject, index|
|
|
|
|
|
buffer_size += 1
|
|
|
|
|
str += ", " unless str.empty?
|
|
|
|
|
puts("---------------------data_statistic: #{subject.id}")
|
|
|
|
@ -23,7 +23,7 @@ namespace :subjects do
|
|
|
|
|
str += ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " +
|
|
|
|
|
"#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " +
|
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
|
puts "buffer_size: #{buffer_size}; subject_id: #{subject.id}; s: #{s.last}; subject: #{subject == s.last};"
|
|
|
|
|
puts "index: #{index}; worker_number: #{Parallel.worker_number}"
|
|
|
|
|
puts "####str: #{str}"
|
|
|
|
|
if buffer_size == 1000 || subject == s.last
|
|
|
|
|
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"
|
|
|
|
|