From 8e63fd902a17666fab966927868b6927426bd4c6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 11 Sep 2019 18:49:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 6 +++--- app/helpers/courses_helper.rb | 2 +- db/migrate/20190911103449_migrate_grade_index.rb | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190911103449_migrate_grade_index.rb 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