mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
PERF: Avoid looking up the same category twice in TopicCreator
.
This commit is contained in:
@ -119,7 +119,6 @@ class TopicCreator
|
||||
topic_params[:subtype] = TopicSubtype.moderator_warning if @opts[:is_warning]
|
||||
|
||||
category = find_category
|
||||
|
||||
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
||||
|
||||
topic_params[:category_id] = category.id if category.present?
|
||||
@ -137,6 +136,7 @@ class TopicCreator
|
||||
end
|
||||
|
||||
def find_category
|
||||
@category ||= begin
|
||||
# PM can't have a category
|
||||
@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))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_tags(topic)
|
||||
if @opts[:tags].blank?
|
||||
|
Reference in New Issue
Block a user