From 2db47f98cda899ddff8fdc03aca899a84676f578 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 8 Sep 2017 13:10:37 +0800 Subject: [PATCH] Avoid allocating an extra array. --- lib/suggested_topics_builder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/suggested_topics_builder.rb b/lib/suggested_topics_builder.rb index cd857875b16..fc7d0cc728d 100644 --- a/lib/suggested_topics_builder.rb +++ b/lib/suggested_topics_builder.rb @@ -24,7 +24,9 @@ class SuggestedTopicsBuilder if @category_id && SiteSetting.limit_suggested_to_category? results = results.where(category_id: @category_id) end - results = results.to_a.reject { |topic| @category_topic_ids.include?(topic.id) } + + results = results.to_a + results.reject! { |topic| @category_topic_ids.include?(topic.id) } unless results.empty? # Keep track of the ids we've added