FIX: Shared draft performance fix + missing avatars

This commit is contained in:
Robin Ward 2018-03-28 15:36:12 -04:00
parent 4b5977aa6a
commit eab64710ff
5 changed files with 43 additions and 28 deletions

View File

@ -71,7 +71,15 @@ class ListController < ApplicationController
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}") list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
if @category.present? && guardian.can_create_shared_draft? 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( shared_drafts = TopicQuery.new(
user, user,
category: SiteSetting.shared_drafts_category, category: SiteSetting.shared_drafts_category,
@ -82,6 +90,7 @@ class ListController < ApplicationController
list.shared_drafts = shared_drafts.topics list.shared_drafts = shared_drafts.topics
end end
end end
end
list.more_topics_url = construct_url_with(:next, list_opts) list.more_topics_url = construct_url_with(:next, list_opts)
list.prev_topics_url = construct_url_with(:prev, list_opts) list.prev_topics_url = construct_url_with(:prev, list_opts)

View File

@ -31,7 +31,7 @@ class Topic < ActiveRecord::Base
def_delegator :notifier, :mute!, :notify_muted! def_delegator :notifier, :mute!, :notify_muted!
def_delegator :notifier, :toggle_mute, :toggle_mute 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| DiscourseEvent.on(:site_setting_saved) do |site_setting|
if site_setting.name.to_s == "slug_generation_method" && site_setting.saved_change_to_value? if site_setting.name.to_s == "slug_generation_method" && site_setting.saved_change_to_value?

View File

@ -26,7 +26,8 @@ class TopicList
end end
end end
attr_accessor :more_topics_url, attr_accessor(
:more_topics_url,
:prev_topics_url, :prev_topics_url,
:draft, :draft,
:draft_key, :draft_key,
@ -37,7 +38,9 @@ class TopicList
:top_tags, :top_tags,
:current_user, :current_user,
:tags, :tags,
:shared_drafts :shared_drafts,
:category
)
def initialize(filter, current_user, topics, opts = nil) def initialize(filter, current_user, topics, opts = nil)
@filter = filter @filter = filter

View File

@ -30,8 +30,9 @@ class TopicListItemSerializer < ListableTopicSerializer
end end
def category_id def category_id
# If it's a shared draft, show the destination topic instead # 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 return object.shared_draft.category_id
end end

View File

@ -482,17 +482,19 @@ class TopicQuery
end end
def apply_shared_drafts(result, category_id, options) 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? if guardian.can_create_shared_draft?
result = result.includes(:shared_draft).references(:shared_draft)
if options[:destination_category_id] if options[:destination_category_id]
destination_category_id = get_category_id(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 end
return result.where("shared_drafts.id IS NULL") unless viewing_shared
end end
result result