PERF: stop adding more topics to search when not needed
The logic of adding additional search results does not seem to be needed anymore. It appears to be a relic of an old implementation. This saves an entire search query for every search made.
This commit is contained in:
parent
42a6c8a85f
commit
3cb41d5429
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue