测试性能

newyslclassrooms
daiao 5 years ago
parent 193e0bcf84
commit d018b48c2d

@ -155,10 +155,11 @@ class ChallengesController < ApplicationController
def index
uid_logger("identifier: #{params}")
bases_column = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position,
challenges.shixun_id, games.identifier, games.status"
@challenges = @shixun.challenges.joins(:games).where(games: {user_id: current_user.id})
.select(bases_column)
#bases_column = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position,
# challenges.shixun_id, games.identifier, games.status"
#@challenges = @shixun.challenges.joins(:games).where(games: {user_id: current_user.id})
# .select(bases_column)
@challenges = @shixun.challenges.fields_for_list
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user
@shixun.increment!(:visits)

@ -79,6 +79,16 @@ class Challenge < ApplicationRecord
end
end
# 开启挑战
def open_game user_id, shixun
game = self.games.where(user_id: user_id).first
if game.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
else
self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : ""
end
end
# # 开启挑战
# def open_game(user_id, shixun)
#
@ -110,6 +120,24 @@ class Challenge < ApplicationRecord
end
end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启
game = games.where(user_id: user_id).take
if game.blank?
position == 1 ? 1 : 0
else
if game.status == 3
shixun.task_pass ? 1 : 0
elsif game.status == 2
2
else
1
end
end
end
def tags_show
if self.challenge_tags.nil?
"--"

@ -19,7 +19,8 @@ if @challenges.present?
json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game
#json.open_game challenge.open_game
challenge.open_game(@user.id, @shixun)
if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
@ -27,6 +28,7 @@ if @challenges.present?
json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position
end
#json.passed challenge.has_passed?(@user.id)
json.status challenge.user_tpi_status
#json.status challenge.user_tpi_status
json.status challenge.user_tpi_status @user.id
end
end

Loading…
Cancel
Save