optimization: prefer relation.none over relation.where("false")
Using `relation.none` instead of `relation.where("false")` avoids an sql query.
This commit is contained in:
@@ -14,7 +14,7 @@ module PostSets
|
|||||||
query
|
query
|
||||||
end
|
end
|
||||||
rescue ::Post::SearchError
|
rescue ::Post::SearchError
|
||||||
::Post.where("false")
|
::Post.none
|
||||||
end
|
end
|
||||||
|
|
||||||
def presenter
|
def presenter
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class Comment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def for_creator(user_id)
|
def for_creator(user_id)
|
||||||
user_id.present? ? where("creator_id = ?", user_id) : where("false")
|
user_id.present? ? where("creator_id = ?", user_id) : none
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_creator_name(user_name)
|
def for_creator_name(user_name)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class PostArchive < ApplicationRecord
|
|||||||
if user_id
|
if user_id
|
||||||
where("updater_id = ?", user_id)
|
where("updater_id = ?", user_id)
|
||||||
else
|
else
|
||||||
where("false")
|
none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class PostFlag < ApplicationRecord
|
|||||||
q = q.where.not(post_id: CurrentUser.user.posts)
|
q = q.where.not(post_id: CurrentUser.user.posts)
|
||||||
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
||||||
else
|
else
|
||||||
q = q.where("false")
|
q = q.none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class PostFlag < ApplicationRecord
|
|||||||
q = q.where.not(post_id: CurrentUser.user.posts)
|
q = q.where.not(post_id: CurrentUser.user.posts)
|
||||||
q = q.where("creator_id = ?", flagger_id)
|
q = q.where("creator_id = ?", flagger_id)
|
||||||
else
|
else
|
||||||
q = q.where("false")
|
q = q.none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user