代码优化

dev_course
daiao 5 years ago
parent 84c714310c
commit b37c4db770

@ -484,16 +484,15 @@ class ShixunsController < ApplicationController
# 中间需要一个过渡动画 # 中间需要一个过渡动画
# TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适 # TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适
def shixun_exec def shixun_exec
current_myshixun = @shixun.current_myshixun(current_user.id)
if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER
tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}")
end end
current_myshixun = @shixun.current_myshixun(current_user.id)
if current_myshixun if current_myshixun
# 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置 # 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置
if current_myshixun.games.count != @shixun.challenges_count ||
current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id)
uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}")
if current_myshixun.games.count != @shixun.challenges_count || current_myshixun.games.map(&:challenge_id).sort != Challenge.where(shixun_id: @shixun.id).pluck(:id).sort
# 这里页面弹框要收到 当前用户myshixun的identifier. # 这里页面弹框要收到 当前用户myshixun的identifier.
tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game")
end end
@ -517,7 +516,7 @@ class ShixunsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
cloud_bridge = edu_setting('cloud_bridge') #cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10 myshixun_identifier = generate_identifier Myshixun, 10
myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
@ -529,12 +528,12 @@ class ShixunsController < ApplicationController
# fork仓库 # fork仓库
project_fork(myshixun, @repo_path, current_user.login) project_fork(myshixun, @repo_path, current_user.login)
rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path )
uid_logger("start openGameInstance") #uid_logger("start openGameInstance")
uri = "#{cloud_bridge}/bridge/game/openGameInstance" #uri = "#{cloud_bridge}/bridge/game/openGameInstance"
logger.info("end openGameInstance") #logger.info("end openGameInstance")
params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last}
uid_logger("openGameInstance params is #{params}") #uid_logger("openGameInstance params is #{params}")
# res = interface_post uri, params, 83, "实训云平台繁忙繁忙等级83" # res = interface_post uri, params, 83, "实训云平台繁忙繁忙等级83"
end end
# 其它创建关卡等操作 # 其它创建关卡等操作
@ -547,7 +546,7 @@ class ShixunsController < ApplicationController
:open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time) :open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time)
end end
# REDO:开启实训时更新关联作品的状态 # REDO:开启实训时更新关联作品的状态-> TODO:这个可以异步。
HomeworksService.new.update_myshixun_work_status myshixun HomeworksService.new.update_myshixun_work_status myshixun
@current_task = myshixun.current_task @current_task = myshixun.current_task

@ -56,7 +56,6 @@ class Myshixun < ApplicationRecord
# status:0 可以测评的,正在测评的 # status:0 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务 # 如果都完成,则当前任务为最后一个任务
def current_task def current_task
current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first
if current_game.blank? if current_game.blank?
if self.status == 1 if self.status == 1

@ -0,0 +1,6 @@
class AddIndexForEvaluateRecord < ActiveRecord::Migration[5.2]
def change
# 增加evalute_records的索引提高查询效率
add_index :evaluate_records, :game_id
end
end
Loading…
Cancel
Save