课程统计优化

dev_tj
daiao 5 years ago
parent 8112e0ca6e
commit fdba605467

@ -12,8 +12,8 @@ class Subjects::UserUsedInfoService < ApplicationService
def call
users_info = []
users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2}, users: {is_test: false})
users.find_in_batches do |u|
Parallel.each(u, in_processes: 5) do |user|
users.find_in_batches(batch_size: 500) do |u|
Parallel.each(u, in_processes: 10) do |user|
myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)}
name = "#{user.lastname}#{user.firstname}"
passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size

@ -125,7 +125,7 @@ namespace :subjects do
subjects.find_each(batch_size: 50) do |subject|
puts("---------------------user_info_statistic: #{subject.id}")
data = Subjects::UserUsedInfoService.call(subject)
Parallel.each(data, in_processes: 5) do |key|
Parallel.each(data, in_processes: 10) do |key|
next if key[:user_id].nil?
str += ", " unless str.empty?
str += ("(#{key[:user_id]}, #{subject.id}, '#{key[:name].gsub(/'/, '"')}', #{key[:passed_myshixun_count]}, " +

Loading…
Cancel
Save