From 7135094316a7113c1d5f6dd79e1e6028fbdaff85 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:12:23 +0800 Subject: [PATCH 1/4] fix reply message api --- app/controllers/messages_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 3dac97899..60a1c171c 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -51,7 +51,8 @@ class MessagesController < ApplicationController def reply return normal_status(2, "回复内容不能为空") if params[:content].blank? - @reply = Message.create!(board: @message.board, root: @message.root, author: current_user, parent: @message, + @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id, + author: current_user, parent: @message, message_detail_attributes: { content: params[:content] }) From 2420ce6a1ba0491b23a25a8e9fd9efe95e8ae52b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 09:29:57 +0800 Subject: [PATCH 2/4] fix bug --- app/tasks/exercise_publish_task.rb | 2 -- app/views/exercise_questions/_exercise_questions.json.jbuilder | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 6f18dc403..282968755 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -84,8 +84,6 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score - Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") - commit_option = { :status => 1, :commit_status => 1, diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 10dc46abf..b5a01ed06 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,5 +1,6 @@ json.question_id question.id -json.question_number question.question_number +# json.question_number question.question_number +json.q_position question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From 7ddd0c4f5d45bf07be04a03e306b12033a88b2c3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:42:39 +0800 Subject: [PATCH 3/4] fix user shixuns list filter bug and n+1 bug --- app/controllers/users/shixuns_controller.rb | 4 ++++ app/decorators/shixun_decorator.rb | 4 ---- app/models/shixun.rb | 4 ++++ app/services/users/shixun_service.rb | 2 +- app/views/users/shixuns/shared/_shixun.json.jbuilder | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/shixuns_controller.rb b/app/controllers/users/shixuns_controller.rb index c4c0d4c07..7b840a0a1 100644 --- a/app/controllers/users/shixuns_controller.rb +++ b/app/controllers/users/shixuns_controller.rb @@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController @count = shixuns.count @shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true) + + ids = @shixuns.map(&:id) + @finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2) + .where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count end private diff --git a/app/decorators/shixun_decorator.rb b/app/decorators/shixun_decorator.rb index 50e2e27eb..4b7a0714a 100644 --- a/app/decorators/shixun_decorator.rb +++ b/app/decorators/shixun_decorator.rb @@ -1,8 +1,4 @@ module ShixunDecorator - def finished_challenges_count(user) - Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count - end - def human_status I18n.t("shixun.status.#{status}") end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9ccefca92..556a4400f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -233,4 +233,8 @@ class Shixun < ApplicationRecord shixun_members.where(role: [1, 2]).exists?(user_id: user.id) end + + def finished_challenges_count(user) + Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count + end end diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index b5e5586f1..4730a5777 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -58,7 +58,7 @@ class Users::ShixunService when 'passed' then 1 when 'processing' then 0 end - relations.where(myshixuns: { status: status }) if status + relations = relations.where(myshixuns: { status: status }) if status relations end diff --git a/app/views/users/shixuns/shared/_shixun.json.jbuilder b/app/views/users/shixuns/shared/_shixun.json.jbuilder index 13cc3a9ee..8427ead58 100644 --- a/app/views/users/shixuns/shared/_shixun.json.jbuilder +++ b/app/views/users/shixuns/shared/_shixun.json.jbuilder @@ -6,4 +6,4 @@ json.name shixun.name json.status shixun.status json.human_status shixun.human_status json.challenges_count shixun.challenges_count -json.finished_challenges_count shixun.finished_challenges_count(user) \ No newline at end of file +json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user) \ No newline at end of file From ab6c1bd682d153ff779b2a1fff97e38176d1c24f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:45:42 +0800 Subject: [PATCH 4/4] fix user projects filter bug --- app/services/users/subject_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index e0d8377c2..7e3eaaa81 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -65,7 +65,7 @@ class Users::SubjectService when 'finished' then subjects.having('finished = 1').map(&:id) end - relations.where(id: subject_ids) if subject_ids.present? + relations = relations.where(id: subject_ids) if subject_ids.present? relations end @@ -75,7 +75,7 @@ class Users::SubjectService when 'applying' then 1 when 'published' then 2 end - relations.where(status: status) if status + relations = relations.where(status: status) if status relations end