diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index f100ac233..c34b76a8a 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -10,17 +10,21 @@ class DiscussesController < ApplicationController if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).joins(challenge: :games) - .where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") + :root_id => nil) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (discusses.hidden = :hidden or discusses.user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) - .joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") @disscuss_count = disscusses.count("discusses.id") end - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) @manger = @container.has_manager?(current_user) + if @manger + @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") + .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset) + logger.info("------#{@discusses.to_sql}") + else + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) + end @current_user = current_user end diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index ee9484131..7da0b7e1f 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -10,7 +10,7 @@ json.hidden discuss.hidden json.manage current_user.manager_of_shixun?(container) json.reward discuss.reward #json.game_url discuss.game_url(container, current_user) -json.game_url "/tasks/#{discuss.identifier}" if @manger +json.game_url "/tasks/#{discuss.identifier}" if @manger && !children # 主贴和回复有一些不同点 if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) diff --git a/app/views/discusses/index.json.jbuilder b/app/views/discusses/index.json.jbuilder index 1b7a95eb3..7ddfb31fb 100644 --- a/app/views/discusses/index.json.jbuilder +++ b/app/views/discusses/index.json.jbuilder @@ -1,8 +1,8 @@ json.disscuss_count @disscuss_count json.all @current_user.admin? json.comments @discusses do |discuss| - json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user } + json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user, children: false} json.children discuss.child_discuss(current_user) do |c_d| - json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user } + json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user, children: true } end end