FIX: Shared draft performance fix + missing avatars
This commit is contained in:
parent
4b5977aa6a
commit
eab64710ff
|
@ -71,15 +71,24 @@ class ListController < ApplicationController
|
|||
|
||||
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
||||
|
||||
if @category.present? && guardian.can_create_shared_draft?
|
||||
shared_drafts = TopicQuery.new(
|
||||
user,
|
||||
category: SiteSetting.shared_drafts_category,
|
||||
destination_category_id: list_opts[:category]
|
||||
).list_latest
|
||||
if guardian.can_create_shared_draft? && @category.present?
|
||||
if @category.id == SiteSetting.shared_drafts_category.to_i
|
||||
# On shared drafts, show the destination category
|
||||
list.topics.each do |t|
|
||||
t.includes_destination_category = true
|
||||
end
|
||||
else
|
||||
# When viewing a non-shared draft category, find topics whose
|
||||
# destination are this category
|
||||
shared_drafts = TopicQuery.new(
|
||||
user,
|
||||
category: SiteSetting.shared_drafts_category,
|
||||
destination_category_id: list_opts[:category]
|
||||
).list_latest
|
||||
|
||||
if shared_drafts.present? && shared_drafts.topics.present?
|
||||
list.shared_drafts = shared_drafts.topics
|
||||
if shared_drafts.present? && shared_drafts.topics.present?
|
||||
list.shared_drafts = shared_drafts.topics
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class Topic < ActiveRecord::Base
|
|||
def_delegator :notifier, :mute!, :notify_muted!
|
||||
def_delegator :notifier, :toggle_mute, :toggle_mute
|
||||
|
||||
attr_accessor :allowed_user_ids, :tags_changed
|
||||
attr_accessor :allowed_user_ids, :tags_changed, :includes_destination_category
|
||||
|
||||
DiscourseEvent.on(:site_setting_saved) do |site_setting|
|
||||
if site_setting.name.to_s == "slug_generation_method" && site_setting.saved_change_to_value?
|
||||
|
|
|
@ -26,18 +26,21 @@ class TopicList
|
|||
end
|
||||
end
|
||||
|
||||
attr_accessor :more_topics_url,
|
||||
:prev_topics_url,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence,
|
||||
:filter,
|
||||
:for_period,
|
||||
:per_page,
|
||||
:top_tags,
|
||||
:current_user,
|
||||
:tags,
|
||||
:shared_drafts
|
||||
attr_accessor(
|
||||
:more_topics_url,
|
||||
:prev_topics_url,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence,
|
||||
:filter,
|
||||
:for_period,
|
||||
:per_page,
|
||||
:top_tags,
|
||||
:current_user,
|
||||
:tags,
|
||||
:shared_drafts,
|
||||
:category
|
||||
)
|
||||
|
||||
def initialize(filter, current_user, topics, opts = nil)
|
||||
@filter = filter
|
||||
|
|
|
@ -30,8 +30,9 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||
end
|
||||
|
||||
def category_id
|
||||
|
||||
# If it's a shared draft, show the destination topic instead
|
||||
if object.category_id == SiteSetting.shared_drafts_category.to_i && object.shared_draft
|
||||
if object.includes_destination_category && object.shared_draft
|
||||
return object.shared_draft.category_id
|
||||
end
|
||||
|
||||
|
|
|
@ -482,17 +482,19 @@ class TopicQuery
|
|||
end
|
||||
|
||||
def apply_shared_drafts(result, category_id, options)
|
||||
viewing_shared = category_id && category_id == SiteSetting.shared_drafts_category.to_i
|
||||
drafts_category_id = SiteSetting.shared_drafts_category.to_i
|
||||
viewing_shared = category_id && category_id == drafts_category_id
|
||||
|
||||
if guardian.can_create_shared_draft?
|
||||
result = result.includes(:shared_draft).references(:shared_draft)
|
||||
|
||||
if options[:destination_category_id]
|
||||
destination_category_id = get_category_id(options[:destination_category_id])
|
||||
return result.where("shared_drafts.category_id" => destination_category_id)
|
||||
topic_ids = SharedDraft.where(category_id: destination_category_id).pluck(:topic_id)
|
||||
return result.where(id: topic_ids)
|
||||
elsif viewing_shared
|
||||
result = result.includes(:shared_draft).references(:shared_draft)
|
||||
else
|
||||
return result.where('topics.category_id != ?', drafts_category_id)
|
||||
end
|
||||
|
||||
return result.where("shared_drafts.id IS NULL") unless viewing_shared
|
||||
end
|
||||
|
||||
result
|
||||
|
|
Loading…
Reference in New Issue