优化实训评论代码

dev_forum
daiao 5 years ago
parent fc40905fdf
commit a22805900d

@ -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

@ -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)

@ -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

Loading…
Cancel
Save