mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 15:46:16 +08:00
PERF: Avoid looking up the same category twice in TopicCreator
.
This commit is contained in:
parent
535c594891
commit
742decc2a1
|
@ -119,7 +119,6 @@ class TopicCreator
|
||||||
topic_params[:subtype] = TopicSubtype.moderator_warning if @opts[:is_warning]
|
topic_params[:subtype] = TopicSubtype.moderator_warning if @opts[:is_warning]
|
||||||
|
|
||||||
category = find_category
|
category = find_category
|
||||||
|
|
||||||
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
||||||
|
|
||||||
topic_params[:category_id] = category.id if category.present?
|
topic_params[:category_id] = category.id if category.present?
|
||||||
|
@ -137,6 +136,7 @@ class TopicCreator
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_category
|
def find_category
|
||||||
|
@category ||= begin
|
||||||
# PM can't have a category
|
# PM can't have a category
|
||||||
@opts.delete(:category) if @opts[:archetype].present? && @opts[:archetype] == Archetype.private_message
|
@opts.delete(:category) if @opts[:archetype].present? && @opts[:archetype] == Archetype.private_message
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ class TopicCreator
|
||||||
Category.find_by(name_lower: @opts[:category].try(:downcase))
|
Category.find_by(name_lower: @opts[:category].try(:downcase))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup_tags(topic)
|
def setup_tags(topic)
|
||||||
if @opts[:tags].blank?
|
if @opts[:tags].blank?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user