Revert "PERF: Don't join on shared drafts unless you have to"
This reverts commit efedd9745f
.
This commit is contained in:
parent
a8f211bd41
commit
4b5977aa6a
|
@ -71,10 +71,7 @@ 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? &&
|
if @category.present? && guardian.can_create_shared_draft?
|
||||||
guardian.can_create_shared_draft? &&
|
|
||||||
@category.id != SiteSetting.shared_drafts_category.to_i
|
|
||||||
|
|
||||||
shared_drafts = TopicQuery.new(
|
shared_drafts = TopicQuery.new(
|
||||||
user,
|
user,
|
||||||
category: SiteSetting.shared_drafts_category,
|
category: SiteSetting.shared_drafts_category,
|
||||||
|
|
|
@ -26,21 +26,18 @@ class TopicList
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor(
|
attr_accessor :more_topics_url,
|
||||||
:more_topics_url,
|
:prev_topics_url,
|
||||||
:prev_topics_url,
|
:draft,
|
||||||
:draft,
|
:draft_key,
|
||||||
:draft_key,
|
:draft_sequence,
|
||||||
:draft_sequence,
|
:filter,
|
||||||
:filter,
|
:for_period,
|
||||||
:for_period,
|
:per_page,
|
||||||
:per_page,
|
: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
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
class TopicListItemSerializer < ListableTopicSerializer
|
class TopicListItemSerializer < ListableTopicSerializer
|
||||||
include TopicTagsMixin
|
include TopicTagsMixin
|
||||||
|
|
||||||
attr_accessor :include_destination_category
|
|
||||||
|
|
||||||
attributes :views,
|
attributes :views,
|
||||||
:like_count,
|
:like_count,
|
||||||
:has_summary,
|
:has_summary,
|
||||||
|
@ -32,9 +30,8 @@ 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 include_destination_category && object.shared_draft
|
if object.category_id == SiteSetting.shared_drafts_category.to_i && object.shared_draft
|
||||||
return object.shared_draft.category_id
|
return object.shared_draft.category_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,26 +9,12 @@ class TopicListSerializer < ApplicationSerializer
|
||||||
:per_page,
|
:per_page,
|
||||||
:top_tags,
|
:top_tags,
|
||||||
:tags,
|
:tags,
|
||||||
:shared_drafts,
|
:shared_drafts
|
||||||
:topics
|
|
||||||
|
|
||||||
|
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
|
||||||
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
|
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
|
||||||
has_many :tags, serializer: TagSerializer, embed: :objects
|
has_many :tags, serializer: TagSerializer, embed: :objects
|
||||||
|
|
||||||
def topics
|
|
||||||
object.topics.map do |t|
|
|
||||||
serializer = TopicListItemSerializer.new(t, scope: scope, root: false)
|
|
||||||
|
|
||||||
if scope.can_create_shared_draft? &&
|
|
||||||
object.category&.id == SiteSetting.shared_drafts_category.to_i
|
|
||||||
|
|
||||||
serializer.include_destination_category = true
|
|
||||||
end
|
|
||||||
|
|
||||||
serializer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def can_create_topic
|
def can_create_topic
|
||||||
scope.can_create?(Topic)
|
scope.can_create?(Topic)
|
||||||
end
|
end
|
||||||
|
|
|
@ -482,19 +482,17 @@ class TopicQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_shared_drafts(result, category_id, options)
|
def apply_shared_drafts(result, category_id, options)
|
||||||
drafts_category_id = SiteSetting.shared_drafts_category.to_i
|
viewing_shared = category_id && 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])
|
||||||
topic_ids = SharedDraft.where(category_id: destination_category_id).pluck(:topic_id)
|
return result.where("shared_drafts.category_id" => destination_category_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
|
||||||
|
|
Loading…
Reference in New Issue