优化代码结构

dev_aliyun_beta
daiao 5 years ago
parent edc1ad4450
commit 4fdc74ac6f

@ -13,8 +13,13 @@ module SubjectsHelper
# 实训路径的所有用户获得的标签
def user_shixun_tags challenge_ids, user_id
logger.info("#####################")
ChallengeTag.joins("join games on challenge_tags.challenge_id = games.challenge_id").
where(challenge_id: challenge_ids, games: {status: 2, user_id: user_id}).pluck("challenge_tags.name").uniq
logger.info("#####################")
pass_challenge_ids = Game.where(status: 2, user_id: user_id, challenge_ids: challenge_ids).pluck(:challenge_id)
ChallengeTag.where(challenge_id: pass_challenge_ids).pluck(:name).uniq
logger.info("#####################")
end
# 金课的课堂状态 0未开课1进行中2已结束

@ -82,9 +82,16 @@ class Subject < ApplicationRecord
end
def my_subject_progress
logger.info("#-----------")
my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}).
pluck(:challenge_id).uniq.size
count = self.subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / self.subject_challenge_count).round(2) * 100).to_i
logger.info("#-----------")
new_challenge_count = Challenge.left_joins(:games)
.where(games: {user_id: current_user.id, status: 2}, shixun_id: shixuns.published_closed)
.uniq.count
logger.info("#-----------")
subject_challenge_count = shixuns.challenges_count
subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / subject_challenge_count).round(2) * 100).to_i
end
def my_consume_time

Loading…
Cancel
Save