优化实训评论

dev_forum
daiao 6 years ago
parent c9d4714ef8
commit bd41f2904f

@ -9,15 +9,18 @@ class DiscussesController < ApplicationController
# 总数,分页使用 # 总数,分页使用
if current_user.admin? if current_user.admin?
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
@discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s,
:root_id => nil).includes(:user, :praise_treads).offset(offset) :root_id => nil).joins(challenge: :games)
.where("discusses.user_id = games.user_id").select("discusses.*, games.identifier")
else else
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
(hidden = :hidden or user_id = :user_id)", (hidden = :hidden or user_id = :user_id)",
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_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 @disscuss_count = disscusses.count
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
end end
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
@manger = @container.has_manager?(current_user)
@current_user = current_user @current_user = current_user
end end

@ -16,6 +16,8 @@ class Challenge < ApplicationRecord
# 参考答案 # 参考答案
has_many :challenge_answers, :dependent => :destroy has_many :challenge_answers, :dependent => :destroy
has_many :exercise_bank_shixun_challenges, :dependent => :destroy has_many :exercise_bank_shixun_challenges, :dependent => :destroy
# 回复
has_many :discusses, :dependent => :destroy
# acts_as_attachable # acts_as_attachable

@ -9,6 +9,7 @@ class Discuss < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy
belongs_to :challenge
after_create :send_tiding after_create :send_tiding
scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) } scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) }

@ -9,7 +9,8 @@ json.shixun_id discuss.dis_id
json.hidden discuss.hidden json.hidden discuss.hidden
json.manage current_user.manager_of_shixun?(container) json.manage current_user.manager_of_shixun?(container)
json.reward discuss.reward json.reward discuss.reward
json.game_url discuss.game_url(container, current_user) #json.game_url discuss.game_url(container, current_user)
json.game_url "/tasks/#{discuss.identifier}" if @manger
# 主贴和回复有一些不同点 # 主贴和回复有一些不同点
if discuss.parent_id if discuss.parent_id
json.can_delete discuss.can_deleted?(current_user) json.can_delete discuss.can_deleted?(current_user)

@ -0,0 +1,11 @@
class ModifyChallengeIdForDiscusses < ActiveRecord::Migration[5.2]
def change
discusses = Discuss.where(challenge_id: nil)
discusses.each do |dis|
challenge_id = Shixun.find(dis.dis_id).challenges.first.id
dis.update_column(:challenge_id, challenge_id)
end
add_index :discusses, :challenge_id
end
end
Loading…
Cancel
Save