mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
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:
@ -21,12 +21,6 @@ class Search
|
|||||||
50
|
50
|
||||||
end
|
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
|
def self.facets
|
||||||
%w(topic category user private_messages tags all_topics)
|
%w(topic category user private_messages tags all_topics)
|
||||||
end
|
end
|
||||||
@ -710,30 +704,12 @@ class Search
|
|||||||
topic_search
|
topic_search
|
||||||
end
|
end
|
||||||
|
|
||||||
add_more_topics_if_expected
|
|
||||||
@results
|
@results
|
||||||
rescue ActiveRecord::StatementInvalid
|
rescue ActiveRecord::StatementInvalid
|
||||||
# In the event of a PG:Error return nothing, it is likely they used a foreign language whose
|
# In the event of a PG:Error return nothing, it is likely they used a foreign language whose
|
||||||
# locale is not supported by postgres
|
# locale is not supported by postgres
|
||||||
end
|
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
|
# If we're searching for a single topic
|
||||||
def single_topic(id)
|
def single_topic(id)
|
||||||
if @opts[:restrict_to_archetype].present?
|
if @opts[:restrict_to_archetype].present?
|
||||||
|
Reference in New Issue
Block a user