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,15 +71,24 @@ 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?
shared_drafts = TopicQuery.new( if @category.id == SiteSetting.shared_drafts_category.to_i
user, # On shared drafts, show the destination category
category: SiteSetting.shared_drafts_category, list.topics.each do |t|
destination_category_id: list_opts[:category] t.includes_destination_category = true
).list_latest 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? if shared_drafts.present? && shared_drafts.topics.present?
list.shared_drafts = shared_drafts.topics list.shared_drafts = shared_drafts.topics
end
end end
end end

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,18 +26,21 @@ class TopicList
end end
end end
attr_accessor :more_topics_url, attr_accessor(
:prev_topics_url, :more_topics_url,
:draft, :prev_topics_url,
:draft_key, :draft,
:draft_sequence, :draft_key,
:filter, :draft_sequence,
:for_period, :filter,
:per_page, :for_period,
:top_tags, :per_page,
:current_user, :top_tags,
:tags, :current_user,
:shared_drafts :tags,
: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