From 9ef61e0af56af430c28deb93b45e7633eaa863a4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 1 Jun 2018 09:44:14 +0800 Subject: [PATCH] PERF: Prefer `exists?` instead of loading AR object. --- app/models/topic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 78cc39584ef..d179b12ee8f 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -655,7 +655,7 @@ SQL end def changed_to_category(new_category) - return true if new_category.blank? || Category.find_by(topic_id: id).present? + return true if new_category.blank? || Category.exists?(topic_id: id) return false if new_category.id == SiteSetting.uncategorized_category_id && !SiteSetting.allow_uncategorized_topics Topic.transaction do