关卡通关情况优化

dev_forum
jingquan huang 5 years ago
parent 0ea08515d4
commit 584d9bd53a

@ -151,10 +151,8 @@ class ChallengesController < ApplicationController
def index def index
uid_logger("identifier: #{params}") uid_logger("identifier: #{params}")
# 通过调试发现 这里includes(:games)性能会慢10倍 # 通过调试发现 这里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 @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
@user = current_user @user = current_user

@ -52,7 +52,7 @@ class Challenge < ApplicationRecord
# 开启挑战 # 开启挑战
def open_game user_id, shixun 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? if game.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
else else
@ -76,7 +76,7 @@ class Challenge < ApplicationRecord
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games # todo: 以前没加索引导致相同关卡,同一用户有多个games
game = games.select{|game| game.user_id == user_id }.last game = games.last
if game.blank? if game.blank?
self.position == 1 ? 1 : 0 self.position == 1 ? 1 : 0

Loading…
Cancel
Save