diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 8333b080d..36f14a5d5 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -450,13 +450,13 @@ class SubjectsController < ApplicationController @user_tags = [] else pass_challenge_ids = pass_games.map(&:challenge_id).uniq # 按道理是不用去重的,但是历史数据与重复 - subject_challenge_count = @subject.shixuns.sum(:challenges_count) + # subject_challenge_count = @subject.shixuns.sum(:challenges_count) # 用户通关获得的标签 @user_tags = ChallengeTag.where(challenge_id: pass_challenge_ids).pluck(:name) # 用户学习进度 @learned = - subject_challenge_count == 0 ? 0 : - ((pass_challenge_ids.size.to_f / subject_challenge_count).round(2) * 100).to_i + @all_score == 0 ? 0 : + ((pass_challenge_ids.size.to_f / @all_score).round(2) * 100).to_i # 用户通关分数 @my_score = Challenge.where(id: pass_challenge_ids).size @time = pass_games.map(&:cost_time).sum diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 6f6c76d04..5ca4eb773 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -111,7 +111,7 @@ module CoursesHelper when "announcement" course.informs.count when "online_learning" - course.subject&.shixuns_count + course.shixuns.count end end diff --git a/db/migrate/20190911103449_migrate_grade_index.rb b/db/migrate/20190911103449_migrate_grade_index.rb new file mode 100644 index 000000000..0128619fa --- /dev/null +++ b/db/migrate/20190911103449_migrate_grade_index.rb @@ -0,0 +1,7 @@ +class MigrateGradeIndex < ActiveRecord::Migration[5.2] + def change + remove_index :grades, [:user_id, :container_id] + add_index :grades, [:container_id, :container_type] + add_index :grades, [:user_id] + end +end