From 584d9bd53ab208c2e6afae0451b789e6b7da70c2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:49:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E9=80=9A=E5=85=B3=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 +--- app/models/challenge.rb | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 8550c20ce..565545713 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,10 +151,8 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id) - # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) + @challenges = @shixun.challenges.fields_for_list.includes(:games).where("games.user_id" => current_user.id) @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 434812234..07a49196d 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -52,7 +52,7 @@ class Challenge < ApplicationRecord # 开启挑战 def open_game user_id, shixun - game = self.games.select([:status, :identifier]).where(user_id: user_id).first + game = self.games.first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else @@ -76,7 +76,7 @@ class Challenge < ApplicationRecord ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = games.select{|game| game.user_id == user_id }.last + game = games.last if game.blank? self.position == 1 ? 1 : 0