From e23e7678e61c89a952fbb07d8fc28859d3f92dd7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:17:25 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a416dfcbe..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -116,12 +116,8 @@ module ExercisesHelper #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = ex_answers.where(user_id:user_id) - answer_choice_array = [] - user_an_choice.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 - end - if answer_choice_array == standard_answer + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer right_users_count += 1 end end @@ -129,7 +125,7 @@ module ExercisesHelper ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) - answer_users_count = answer_this_choice.count + answer_users_count = answer_this_choice.size if effictive_users_count == 0 answer_percent = 0.0 else @@ -170,7 +166,6 @@ module ExercisesHelper else answer_percent = (user_count / effictive_users_count.to_f ).round(3) end - answer_option = { :choice_position => index+1, :choice_text => s_choice_text, @@ -200,9 +195,9 @@ module ExercisesHelper question_answer_infos.push(wrong_answer_position) elsif ex.question_type == Exercise::SUBJECTIVE #主观题 ex_score = ex&.question_score - full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 - no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + full_scores = effictive_users.search_exercise_answer("score",ex_score).size #满分人数 + no_full_scores = effictive_users.exercise_no_full_scores(ex_score).size #部分分数人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).size #包含为0分的,及未评阅的 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 @@ -415,7 +410,7 @@ module ExercisesHelper user_answer_content = answer_choice_array.sort standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.count > 0 + if standard_answer.size > 0 q_score_1 = q.question_score # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else From 9a859c567547f5e183d1355fd41c2aea5b01c020 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:21:33 +0800 Subject: [PATCH 02/19] fixbug --- app/helpers/exercises_helper.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..1dd6c7452 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,13 +115,14 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + percent = 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) From a56da584d1fa4e1c2bb9c028bea67e9e592c9037 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:29:17 +0800 Subject: [PATCH 03/19] fixbug --- app/controllers/exercises_controller.rb | 6 +++--- app/helpers/exercises_helper.rb | 15 +++++++-------- app/models/exercise.rb | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index fe04e04f8..09b237221 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -203,13 +203,13 @@ class ExercisesController < ApplicationController else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 - @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 + @user_commit_counts = @exercise.exercise_users.where(commit_status:1).size #已提交的用户数 end @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).count #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 if @ex_status == 1 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1dd6c7452..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,14 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - percent = 0.0 + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e7d141ea9..a46fded25 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -178,13 +178,12 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.first.commit_status end - if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end - user_status end From 4fbf6ad4e14e94e105c384a831b9d0bb20c0a4d5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 09:36:15 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e2df181f0..ae7335496 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -45,6 +45,8 @@ class AccountsController < ApplicationController @user.activate # 必须要用save操作,密码的保存是在users中 if @user.save! + # todo user_extension + UserExtension.create!(user_id: @user.id) # 注册完成,手机号或邮箱想可以奖励500金币 RewardGradeService.call( @user, From 81e52b9e18d9bcacda1a174feb29a08fa6aca7bb Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 09:36:16 +0800 Subject: [PATCH 05/19] modify check mail and phone valid --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f9516b9e4..fbb1fef12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,7 @@ class ApplicationController < ActionController::Base # 考虑到安全参数问题,多一次查询,去掉Union user = User.where(phone: login).first || User.where(mail: login).first if type.to_i == 1 && !user.nil? - tip_exception("该手机号码或邮箱已被注册") + tip_exception(-2, "该手机号码或邮箱已被注册") elsif type.to_i == 2 && user.nil? tip_exception("该手机号码或邮箱未注册") end From 6998dd8286f3c0a2bb486e55c5519af7e2f66f3e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:36:35 +0800 Subject: [PATCH 06/19] fixbug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 09b237221..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1204,7 +1204,7 @@ class ExercisesController < ApplicationController #筛选/分类,排序 order = params[:order] - if @exercise_users_list.exists? && @exercise_users_list.size > 0 + if @exercise_users_list.present? && @exercise_users_list.size > 0 @exercise_users_count = @exercise_users_list.size #当前显示的全部成员数量 teacher_reviews = @exercise_users_list.exercise_review teacher_unreviews = @exercise_users_list.exercise_unreview From 8a78d0d3754a0e9a36c217af1c8192030d4aab2f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:53:27 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..9ac02c82a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,10 +115,12 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + effictive_users.transaction do + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 From 6d535cd4bc057298e1b94b0d05dc9ebb258df5b7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 10:02:21 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=88=E4=BD=9C=E8=80=85=E7=9A=84=E6=89=8B=E6=9C=BA=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8f6dd23a4..599be4cde 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -662,8 +662,8 @@ class ShixunsController < ApplicationController school_name = "%#{params[:school_name].to_s.strip}%" if user_name.present? || school_name.present? @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND - LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'") + (LOWER(users.lastname) LIKE ? or users.phone like ?) AND LOWER(schools.name) LIKE + ?", user_name, user_name, school_name) else @users = User.none end From 804fc5eea20fc717816b775f9cfa3c887ae230b7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:19:55 +0800 Subject: [PATCH 09/19] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..39d793b5a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController @paging_type = params[:sort].to_s end - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9ac02c82a..24c296558 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -84,7 +84,7 @@ module ExercisesHelper end #试卷的统计结果页面计算各题的 - def exercise_commit_result(questions,user_ids) + def exercise_commit_result(questions,user_ids,commit_users) question_infos = [] percent = 0.0 questions.each do |ex| @@ -115,9 +115,9 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - effictive_users.transaction do - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + commit_users.transaction do + commit_users.each do |user| + answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From 6af86402cbe654d395cb65e5f802557ec6c08772 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:22:18 +0800 Subject: [PATCH 10/19] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 24c296558..0cfcd5336 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -117,7 +117,7 @@ module ExercisesHelper #计算每个问题的答案人数 commit_users.transaction do commit_users.each do |user| - answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From e480a8e2e54e1e2ebb13737d19a1e270c51ee802 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 16 Jul 2019 10:33:10 +0800 Subject: [PATCH 11/19] rep content is not exit --- app/controllers/games_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 217f1839a..e5cfaf2a6 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -490,7 +490,10 @@ class GamesController < ApplicationController uid_logger("--rep_content: path is #{path}") begin @content = git_fle_content(@myshixun.repo_path, path) || "" - rescue + rescue Exception => e + if e.status == -1 + tip_exception(-3, "#{e.message}") + end if params[:retry].to_i == 1 begin begin From 0e2ba6296779ef30ea024a3a939445457e426891 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 10:36:22 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_extension.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 458d31989..5a0dc8a37 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -3,7 +3,7 @@ class UserExtension < ApplicationRecord enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 } belongs_to :user, touch: true - belongs_to :school + belongs_to :school, optional: true belongs_to :department, optional: true def identity_text From 6d6098452f2732e719a626024e1e33245eba01e8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:37:39 +0800 Subject: [PATCH 13/19] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 39d793b5a..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController @paging_type = params[:sort].to_s end - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0cfcd5336..f5d341aae 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -84,12 +84,12 @@ module ExercisesHelper end #试卷的统计结果页面计算各题的 - def exercise_commit_result(questions,user_ids,commit_users) + def exercise_commit_result(questions,user_ids) question_infos = [] percent = 0.0 questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers + ex_answers = ex.exercise_answers.includes(:exercise_choice) if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -115,12 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - commit_users.transaction do - commit_users.each do |user| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end + # commit_users.transaction do + # + # end + user_ids.each do |user_id| + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 From efa5e8b5bb79242a4e297227f07731ffe6c3e09c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 16 Jul 2019 10:56:54 +0800 Subject: [PATCH 14/19] =?UTF-8?q?rep=20=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E7=AB=8B=E5=8D=B3=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=90=8E=E5=8F=B0=E6=A3=80=E6=B5=8B=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 31 ++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e5cfaf2a6..c951340f8 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -477,7 +477,7 @@ class GamesController < ApplicationController # 获取版本库文件内容 # 注:如果本身path传错,内容肯定也为空;fork成功后,可能短时间内也获取不到版本库内容 # params[:status] 1: 目录树点击的请求 0:正常自动加载 - # 返回参数status : -3 需要重试,带retry参数;-1 给出提示 + # 返回参数status : -1 系统统一报错提示;-3 需要轮训重试,带retry参数;-4 立即重试 def rep_content challenge_path = @game.challenge.try(:path) if challenge_path.blank? @@ -491,24 +491,9 @@ class GamesController < ApplicationController begin @content = git_fle_content(@myshixun.repo_path, path) || "" rescue Exception => e - if e.status == -1 - tip_exception(-3, "#{e.message}") - end + # 思路: 异常首先应该考虑去恢复 if params[:retry].to_i == 1 begin - begin - # 检测TPM对应的路径代码是否正常 - git_fle_content(@myshixun.shixun.repo_path, path) - rescue Exception => e - uid_logger_error("#{e.message}") - # 如果已发布的TPM实训也不能获取到内容,那么肯定是版本库异常了 - if @myshixun.shixun.try(:status) < 2 - tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") - else - tip_exception("代码获取异常,请联系系统管理员") - end - end - # 如果模板没有问题,则通过中间层检测实训仓库是否异常 # 监测版本库HEAD是否存在,不存在则取最新的HEAD gitUrl = repo_url @myshixun.repo_path @@ -531,11 +516,17 @@ class GamesController < ApplicationController end rescue Exception => e uid_logger_error(e.message) - # 报错继续retry - tip_exception(-3, "#{e.message}") + + if @myshixun.shixun.try(:status) < 2 + tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") + else + # 报错继续retry + tip_exception(-3, "#{e.message}") + end end end - tip_exception(-3, "#{e.message}") + # 有异常了,立即重试 + tip_exception(-4, e.message) end end From a2779baf36794781c3606cb25abc919a8526d010 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 11:02:10 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 132 +++++++++++------- .../homework_commons/shixuns.json.jbuilder | 27 +++- 2 files changed, 103 insertions(+), 56 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1f7433f8b..ccadba89c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -822,66 +822,98 @@ class HomeworkCommonsController < ApplicationController @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") @homework_category = @main_catrgory.take.course_second_categories - ## 我的实训 - @shixuns = - if params[:order_by] == 'mine' - current_user.my_shixuns.unhidden - else - if current_user.admin? - Shixun.unhidden - else - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - - @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden - end - end + search = params[:search] + type = params[:type] + # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) + if current_user.admin? + @shixuns = Shixun.unhidden + else + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - ## 方向 - if params[:tag_level].present? && params[:tag_id].present? - @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) - case params[:tag_level].to_i - when 1 #大类 - @search_tags = Repertoire.find(params[:tag_id].to_i).name - when 2 #子类 - @search_tags = SubRepertoire.find(params[:tag_id].to_i).name - when 3 #tag - tag = TagRepertoire.find(params[:tag_id].to_i) - @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" - end + @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden end - ## 搜索关键字创建者、实训名称、院校名称 - if params[:keyword].present? - keyword = params[:keyword].strip - @shixuns = @shixuns.joins(user: [user_extenison: :school]). - where("schools.name like '%#{keyword}%' - or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct - end + # 实训的所有标签 + @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct - ## 筛选 难度 - if params[:diff].present? && params[:diff].to_i != 0 - @shixuns = @shixuns.where(trainee: params[:diff]) + if params[:search] && params[:search].strip != "" + @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?", + "%#{search}%", "%#{search}%").distinct end - ## 排序参数 - bsort = params[:sort] || 'desc' - case params[:order_by] || 'hot' - when 'hot' - @shixuns = @shixuns.order("myshixuns_count #{bsort}") - when 'mine' - @shixuns = @shixuns.order("shixuns.created_at #{bsort}") - else - @shixuns = @shixuns.order("myshixuns_count #{bsort}") + unless type.blank? || type == "all" + @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct end - @total_count = @shixuns.count + @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc") + @shixuns_count = @shixuns.size ## 分页参数 - page = params[:page] || 1 - limit = params[:limit] || 15 - - @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) + page = params[:page] || 1 + @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10) + + # 新版用下面的代码 + # ## 我的实训 + # @shixuns = + # if params[:order_by] == 'mine' + # current_user.my_shixuns.unhidden + # else + # if current_user.admin? + # Shixun.unhidden + # else + # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + # + # @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + # end + # end + # + # ## 方向 + # if params[:tag_level].present? && params[:tag_id].present? + # @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) + # case params[:tag_level].to_i + # when 1 #大类 + # @search_tags = Repertoire.find(params[:tag_id].to_i).name + # when 2 #子类 + # @search_tags = SubRepertoire.find(params[:tag_id].to_i).name + # when 3 #tag + # tag = TagRepertoire.find(params[:tag_id].to_i) + # @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" + # end + # end + # + # ## 搜索关键字创建者、实训名称、院校名称 + # if params[:keyword].present? + # keyword = params[:keyword].strip + # @shixuns = @shixuns.joins(user: [user_extenison: :school]). + # where("schools.name like '%#{keyword}%' + # or concat(lastname, firstname) like '%#{keyword}%' + # or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + # end + # + # ## 筛选 难度 + # if params[:diff].present? && params[:diff].to_i != 0 + # @shixuns = @shixuns.where(trainee: params[:diff]) + # end + # + # ## 排序参数 + # bsort = params[:sort] || 'desc' + # case params[:order_by] || 'hot' + # when 'hot' + # @shixuns = @shixuns.order("myshixuns_count #{bsort}") + # when 'mine' + # @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + # else + # @shixuns = @shixuns.order("myshixuns_count #{bsort}") + # end + # + # @total_count = @shixuns.count + # + # ## 分页参数 + # page = params[:page] || 1 + # limit = params[:limit] || 15 + # + # @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) + # end def create_shixun_homework diff --git a/app/views/homework_commons/shixuns.json.jbuilder b/app/views/homework_commons/shixuns.json.jbuilder index 8bfeea562..bd97f5e8d 100644 --- a/app/views/homework_commons/shixuns.json.jbuilder +++ b/app/views/homework_commons/shixuns.json.jbuilder @@ -1,12 +1,27 @@ +# json.shixun_list @shixuns do |shixun| +# json.shixun_identifier shixun.identifier +# json.name shixun.name +# json.creator shixun.user&.full_name +# json.creator_login shixun.user&.login +# json.school shixun.user&.school_name +# json.myshixuns_count shixun.myshixuns_count +# json.level level_to_s(shixun.trainee) +# json.challenge_tags shixun.challenge_tags_name +# end + json.shixun_list @shixuns do |shixun| - json.shixun_identifier shixun.identifier - json.name shixun.name - json.creator shixun.user&.full_name - json.creator_login shixun.user&.login - json.school shixun.user&.school_name + json.shixun_id shixun.id + json.identifier shixun.identifier + json.shixun_name shixun.name json.myshixuns_count shixun.myshixuns_count + json.school shixun.user&.school_name + json.creator shixun.user&.full_name json.level level_to_s(shixun.trainee) - json.challenge_tags shixun.challenge_tags_name +end + +json.tags @tags do |tag| + json.tag_id tag.id + json.tag_name tag.name end json.shixuns_count @total_count From b5ea3a60ca8536d65972cdea58025ed39778681c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:03:01 +0800 Subject: [PATCH 16/19] fixbug --- app/helpers/exercises_helper.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index f5d341aae..8b0ad2ad5 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,17 +113,35 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - - #计算每个问题的答案人数 - # commit_users.transaction do - # + # if ex.question_type == Exercise::MULTIPLE #多选题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # else #单选题和判断题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end # end user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + if ex.question_type == Exercise::MULTIPLE + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + else + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + if [answer_choice_array] == standard_answer + right_users_count += 1 + end end end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 From 1aa5e6972eb4341e5f71400cf1659aef56a83fa4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:06:20 +0800 Subject: [PATCH 17/19] fixbug --- app/helpers/exercises_helper.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8b0ad2ad5..7cd854d61 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,21 +113,6 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - # if ex.question_type == Exercise::MULTIPLE #多选题 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # else #单选题和判断题 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position - # if [answer_choice_array] == standard_answer - # right_users_count += 1 - # end - # end - # end user_ids.each do |user_id| if ex.question_type == Exercise::MULTIPLE answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq @@ -135,7 +120,7 @@ module ExercisesHelper right_users_count += 1 end else - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position if [answer_choice_array] == standard_answer right_users_count += 1 end From e132593ce7c06ad34b72a66ff2d119f98ef86992 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:11:16 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87=E7=9A=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7cd854d61..dfb6e4237 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,13 +113,15 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - user_ids.each do |user_id| - if ex.question_type == Exercise::MULTIPLE + if ex.question_type == Exercise::MULTIPLE #多选题 + user_ids.each do |user_id| answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end - else + end + else #单选题和判断题 + user_ids.each do |user_id| answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position if [answer_choice_array] == standard_answer right_users_count += 1 From 4e8f18a30bd23fe70097b69b56587f2b888b8e7b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 13:43:03 +0800 Subject: [PATCH 19/19] enable elasticsearch && add elasticsearch config --- .gitignore | 1 + Gemfile | 2 +- Gemfile.lock | 14 ++++++++++++++ app/models/challenge_tag.rb | 3 +-- app/models/course.rb | 3 +-- app/models/memo.rb | 3 +-- app/models/searchable/memo.rb | 1 + app/models/searchable/shixun.rb | 2 +- app/models/searchable/subject.rb | 12 +++--------- app/models/shixun.rb | 3 +-- app/models/stage.rb | 3 +-- app/models/subject.rb | 3 +-- app/models/user.rb | 3 +-- config/elasticsearch.yml.example | 13 +++++++++++++ config/initializers/elasticsearch.rb | 2 ++ 15 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 config/elasticsearch.yml.example create mode 100644 config/initializers/elasticsearch.rb diff --git a/.gitignore b/.gitignore index 4f52644ff..09b9eab36 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ /config/secrets.yml /config/redis.yml +/config/elasticsearch.yml public/upload.html /config/configuration.yml diff --git a/Gemfile b/Gemfile index 3450c06e8..4cabd09b9 100644 --- a/Gemfile +++ b/Gemfile @@ -90,4 +90,4 @@ gem 'sinatra' gem 'bulk_insert' # elasticsearch -# gem 'searchkick' +gem 'searchkick' diff --git a/Gemfile.lock b/Gemfile.lock index 728bbc672..94893687b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,14 @@ GEM connection_pool (2.2.2) crass (1.0.4) diff-lcs (1.3) + elasticsearch (7.2.0) + elasticsearch-api (= 7.2.0) + elasticsearch-transport (= 7.2.0) + elasticsearch-api (7.2.0) + multi_json + elasticsearch-transport (7.2.0) + faraday + multi_json erubi (1.7.1) execjs (2.7.0) faraday (0.15.4) @@ -100,6 +108,7 @@ GEM grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) + hashie (3.6.0) htmlentities (4.3.4) httparty (0.16.2) multi_xml (>= 0.5.2) @@ -255,6 +264,10 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + searchkick (3.1.3) + activemodel (>= 4.2) + elasticsearch (>= 5) + hashie selenium-webdriver (3.14.0) childprocess (~> 0.5) rubyzip (~> 1.2) @@ -344,6 +357,7 @@ DEPENDENCIES ruby-ole rubyzip sass-rails (~> 5.0) + searchkick selenium-webdriver sidekiq simple_xlsx_reader diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb index b68e1792c..acea39770 100644 --- a/app/models/challenge_tag.rb +++ b/app/models/challenge_tag.rb @@ -1,6 +1,5 @@ class ChallengeTag < ApplicationRecord - # TODO: ES feature - # include Searchable::Dependents::ChallengeTag + include Searchable::Dependents::ChallengeTag belongs_to :challenge, counter_cache: true belongs_to :challenge_choose, optional: true diff --git a/app/models/course.rb b/app/models/course.rb index 77ff6c46d..b2835fc21 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,6 +1,5 @@ class Course < ApplicationRecord - # TODO: ES feature - # include Searchable::Course + include Searchable::Course has_many :boards, dependent: :destroy diff --git a/app/models/memo.rb b/app/models/memo.rb index 3cb074a78..610a7684d 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,6 +1,5 @@ class Memo < ApplicationRecord - # TODO: ES feature - # include Searchable::Memo + include Searchable::Memo has_many :memo_tag_repertoires, :dependent => :destroy has_many :tag_repertoires, :through => :memo_tag_repertoires diff --git a/app/models/searchable/memo.rb b/app/models/searchable/memo.rb index 5aa9d5fe2..648f4671b 100644 --- a/app/models/searchable/memo.rb +++ b/app/models/searchable/memo.rb @@ -26,6 +26,7 @@ module Searchable::Memo { descendants_contents: Util.map_or_pluck(descendants, :content) .map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] } + .join('
') } end diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index 1f39dcd76..e4108024c 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -31,7 +31,7 @@ module Searchable::Shixun .each_with_index.map { |subject, index| "第#{index + 1}关 #{subject}" } { - challenge_names: challenge_names, + challenge_names: challenge_names.join(' '), challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ') } end diff --git a/app/models/searchable/subject.rb b/app/models/searchable/subject.rb index feec41a3c..94a5c1383 100644 --- a/app/models/searchable/subject.rb +++ b/app/models/searchable/subject.rb @@ -31,15 +31,9 @@ module Searchable::Subject end def searchable_stages_data - subject_stages = - stages.map do |stage| - { - name: stage.name, - description: Util.extract_content(stage.description)[0..Searchable::MAXIMUM_LENGTH] - } - end - - { subject_stages: subject_stages} + subject_stages = stages.map { |stage| "#{stage.name} #{Util.extract_content(stage.description)}"[0..Searchable::MAXIMUM_LENGTH] } + + { subject_stages: subject_stages.join('
') } end def to_searchable_json diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 0925f4fa0..d274f0a6d 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,6 +1,5 @@ class Shixun < ApplicationRecord - # TODO: ES feature - # include Searchable::Shixun + include Searchable::Shixun # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 # hide_code: 隐藏代码窗口 diff --git a/app/models/stage.rb b/app/models/stage.rb index ee4e969dd..d255cddeb 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -1,6 +1,5 @@ class Stage < ApplicationRecord - # TODO: ES feature - # include Searchable::Dependents::Stage + include Searchable::Dependents::Stage belongs_to :subject, counter_cache: true diff --git a/app/models/subject.rb b/app/models/subject.rb index b9dd49f5a..064efb7a6 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -2,8 +2,7 @@ # 可以在初始创建的时候 class Subject < ApplicationRecord - # TODO: ES feature - # include Searchable::Subject + include Searchable::Subject #status :0 编辑中 1 审核中 2 发布 belongs_to :repertoire diff --git a/app/models/user.rb b/app/models/user.rb index 89918551e..fb1a47f2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,6 @@ class User < ApplicationRecord include Watchable - # TODO: ES feature - # include Searchable::Dependents::User + include Searchable::Dependents::User # Account statuses STATUS_ANONYMOUS = 0 diff --git a/config/elasticsearch.yml.example b/config/elasticsearch.yml.example new file mode 100644 index 000000000..cbecb85d7 --- /dev/null +++ b/config/elasticsearch.yml.example @@ -0,0 +1,13 @@ +defaults: &defaults + url: http://localhost:9200 + +development: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/' + # url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com' diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb new file mode 100644 index 000000000..5ab7d3e62 --- /dev/null +++ b/config/initializers/elasticsearch.rb @@ -0,0 +1,2 @@ +redis_config = Rails.application.config_for(:elasticsearch) +ENV['ELASTICSEARCH_URL'] = redis_config['url']