@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController
@count = shixuns.count
@shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true)
ids = @shixuns.map(&:id)
@finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2)
.where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count
end
private
@ -1,8 +1,4 @@
module ShixunDecorator
def finished_challenges_count(user)
Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count
def human_status
I18n.t("shixun.status.#{status}")
@ -233,4 +233,8 @@ class Shixun < ApplicationRecord
shixun_members.where(role: [1, 2]).exists?(user_id: user.id)
@ -58,7 +58,7 @@ class Users::ShixunService
when 'passed' then 1
when 'processing' then 0
relations.where(myshixuns: { status: status }) if status
relations = relations.where(myshixuns: { status: status }) if status
relations
@ -6,4 +6,4 @@ json.name shixun.name
json.status shixun.status
json.human_status shixun.human_status
json.challenges_count shixun.challenges_count
json.finished_challenges_count shixun.finished_challenges_count(user)
json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user)