From 15a2f16453657679626cdd28732f0b656b53977c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 31 May 2019 08:34:12 +0800 Subject: [PATCH] remove shixuns evaluate count code --- app/services/games_service.rb | 2 -- app/services/management/school_report_service.rb | 10 +++++++--- .../managements/schools/_statistics_list.html.erb | 3 ++- ...0190531002049_remove_evaluate_count_from_shixuns.rb | 9 +++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20190531002049_remove_evaluate_count_from_shixuns.rb diff --git a/app/services/games_service.rb b/app/services/games_service.rb index d293b0f2..253b5bcd 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -533,7 +533,6 @@ class GamesService # 更新评测次数 game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) - # shixun.increment!(:evaluate_count) # 清空代码评测信息 msg = game.run_code_message msg.update_attributes(:status => 0, :message => nil) if msg.present? @@ -694,7 +693,6 @@ class GamesService :evaluate_count]).find_by_identifier(params[:identifier]) # 更新评测次数 game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) - # game.challenge.shixun.increment!(:evaluate_count) # 选择题如果通关了,则不让再评测 if game.status == 2 diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index b102c01a..406460cc 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -3,8 +3,9 @@ class Management::SchoolReportService attr_reader :params + # 因为实在太慢了,所以不开放 shixun_evaluate_count 排序 sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count, - :course_count, :active_course_count, :nearly_course_time, :shixun_count, :shixun_evaluate_count, + :course_count, :active_course_count, :nearly_course_time, :shixun_count, default_by: :teacher_count, default_direction: :desc def initialize(params) @@ -49,7 +50,8 @@ class Management::SchoolReportService shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids }) .group('school_id').count - evaluate_count_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids }) + evaluate_count_map = Game.joins(challenge: { shixun: { creator: :user_extensions } }) + .where(user_extensions: { identity: User::TEACHER, school_id: ids }) .group('school_id').sum(:evaluate_count) schools.map do |school| @@ -90,7 +92,9 @@ class Management::SchoolReportService .select("#{base_query_column}, COUNT(*) shixun_count") when 'shixun_evaluate_count' then schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id') - .select("#{base_query_column}, SUM(sx.evaluate_count) shixun_evaluate_count") + .joins('LEFT JOIN challenges cs ON cs.shixun_id = sx.id') + .joins('LEFT JOIN games ON games.challenge_id = cs.id') + .select("#{base_query_column}, SUM(games.evaluate_count) shixun_evaluate_count") when 'nearly_course_time' then schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') .joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id') diff --git a/app/views/managements/schools/_statistics_list.html.erb b/app/views/managements/schools/_statistics_list.html.erb index 0a0cb75d..559ff05c 100644 --- a/app/views/managements/schools/_statistics_list.html.erb +++ b/app/views/managements/schools/_statistics_list.html.erb @@ -10,7 +10,8 @@ <%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %> <%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %> <%= sort_tag('创建实训数', name: 'shixun_count', path: school_report_managements_path) %> - <%= sort_tag('评测次数', name: 'shixun_evaluate_count', path: school_report_managements_path) %> + + 评测次数 <%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %> <%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %> <%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %> diff --git a/db/migrate/20190531002049_remove_evaluate_count_from_shixuns.rb b/db/migrate/20190531002049_remove_evaluate_count_from_shixuns.rb new file mode 100644 index 00000000..591f2ffd --- /dev/null +++ b/db/migrate/20190531002049_remove_evaluate_count_from_shixuns.rb @@ -0,0 +1,9 @@ +class RemoveEvaluateCountFromShixuns < ActiveRecord::Migration + def up + remove_column :shixuns, :evaluate_count + end + + def down + add_column :shixuns, :evaluate_count, :integer, default: 0 + end +end