search: optimize username metatags.
Optimize metatag searches involving usernames, including user:, approver:, appealer:, commenter:, upvoter:, etc. Do `User.find_by_name` instead of `User.name_matches` because this fetches the user upfront instead of doing it inside a subquery. Using a subquery makes the SQL more complicated and leads to worse query plans. This especially helps searches involving multiple username metatags.
This commit is contained in:
@@ -266,7 +266,9 @@ class PostQueryBuilder
|
|||||||
when "none"
|
when "none"
|
||||||
Post.where(field => nil)
|
Post.where(field => nil)
|
||||||
else
|
else
|
||||||
Post.where(field => User.name_matches(username))
|
user = User.find_by_name(username)
|
||||||
|
return Post.none if user.nil?
|
||||||
|
Post.where(field => user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -278,7 +280,9 @@ class PostQueryBuilder
|
|||||||
elsif username == "none"
|
elsif username == "none"
|
||||||
Post.where("NOT EXISTS (#{subquery.to_sql})")
|
Post.where("NOT EXISTS (#{subquery.to_sql})")
|
||||||
elsif block.nil?
|
elsif block.nil?
|
||||||
subquery = subquery.where(field => User.name_matches(username))
|
user = User.find_by_name(username)
|
||||||
|
return Post.none if user.nil?
|
||||||
|
subquery = subquery.where(field => user)
|
||||||
Post.where("EXISTS (#{subquery.to_sql})")
|
Post.where("EXISTS (#{subquery.to_sql})")
|
||||||
else
|
else
|
||||||
subquery = subquery.merge(block.call(username))
|
subquery = subquery.merge(block.call(username))
|
||||||
|
|||||||
Reference in New Issue
Block a user