Skip to content

A platform for community discussion. Free, open, simple.

PERF: stop adding more topics to search when not needed

Sam Saffron3cb41d542999
diff --git a/lib/search.rb b/lib/search.rb
index fa0a0d769d1..d95ec378c93 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -21,12 +21,6 @@ class Search
50
end
- # Sometimes we want more topics than are returned due to exclusion of dupes. This is the
- # factor of extra results we'll ask for.
- def self.burst_factor
- 3
- end
-
def self.facets
%w(topic category user private_messages tags all_topics)
end
@@ -710,30 +704,12 @@ class Search
topic_search
end
- add_more_topics_if_expected
@results
rescue ActiveRecord::StatementInvalid
# In the event of a PG:Error return nothing, it is likely they used a foreign language whose
# locale is not supported by postgres
end
- # Add more topics if we expected them
- def add_more_topics_if_expected
- expected_topics = 0
- expected_topics = Search.facets.size unless @results.type_filter.present?
- expected_topics = Search.per_facet * Search.facets.size if @results.type_filter == 'topic'
- expected_topics -= @results.posts.length
- if expected_topics > 0
- extra_posts = posts_query(expected_topics * Search.burst_factor)
- extra_posts = extra_posts.where("posts.topic_id NOT in (?)", @results.posts.map(&:topic_id)) if @results.posts.present?
- extra_posts.each do |post|
- @results.add(post)
- expected_topics -= 1
- break if expected_topics == 0
- end
- end
- end
-
# If we're searching for a single topic
def single_topic(id)
if @opts[:restrict_to_archetype].present?