mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
PERF: Add partial index for non-pm search.
This commit is contained in:
+26
-9
@@ -818,22 +818,37 @@ class Search
|
||||
.joins("LEFT JOIN categories ON categories.id = topics.category_id")
|
||||
|
||||
is_topic_search = @search_context.present? && @search_context.is_a?(Topic)
|
||||
|
||||
posts = posts.where("topics.visible") unless is_topic_search
|
||||
|
||||
if type_filter === "private_messages" || (is_topic_search && @search_context.private_message?)
|
||||
posts = posts.where("topics.archetype = ?", Archetype.private_message)
|
||||
posts = posts
|
||||
.where(
|
||||
"topics.archetype = ? AND post_search_data.private_message",
|
||||
Archetype.private_message
|
||||
)
|
||||
|
||||
unless @guardian.is_admin?
|
||||
posts = posts.private_posts_for_user(@guardian.user)
|
||||
end
|
||||
unless @guardian.is_admin?
|
||||
posts = posts.private_posts_for_user(@guardian.user)
|
||||
end
|
||||
elsif type_filter === "all_topics"
|
||||
private_posts = posts.where("topics.archetype = ?", Archetype.private_message)
|
||||
private_posts = private_posts.private_posts_for_user(@guardian.user)
|
||||
private_posts = posts
|
||||
.where(
|
||||
"topics.archetype = ? AND post_search_data.private_message",
|
||||
Archetype.private_message
|
||||
)
|
||||
.private_posts_for_user(@guardian.user)
|
||||
|
||||
posts = posts.where("topics.archetype <> ?", Archetype.private_message).or(private_posts)
|
||||
posts = posts
|
||||
.where(
|
||||
"topics.archetype <> ? AND NOT post_search_data.private_message",
|
||||
Archetype.private_message
|
||||
)
|
||||
.or(private_posts)
|
||||
else
|
||||
posts = posts.where("topics.archetype <> ?", Archetype.private_message)
|
||||
posts = posts.where(
|
||||
"topics.archetype <> ? AND NOT post_search_data.private_message",
|
||||
Archetype.private_message
|
||||
)
|
||||
end
|
||||
|
||||
if @term.present?
|
||||
@@ -1162,6 +1177,8 @@ class Search
|
||||
query.includes(topic: topic_eager_loads)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Limited for performance reasons since `TS_HEADLINE` is slow when the text
|
||||
# document is too long.
|
||||
MAX_LENGTH_FOR_HEADLINE = 2500
|
||||
|
||||
Reference in New Issue
Block a user