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
|
||||
end
|
||||
rescue ::Post::SearchError
|
||||
::Post.where("false")
|
||||
::Post.none
|
||||
end
|
||||
|
||||
def presenter
|
||||
|
||||
@@ -64,7 +64,7 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def for_creator_name(user_name)
|
||||
|
||||
@@ -22,7 +22,7 @@ class PostArchive < ApplicationRecord
|
||||
if user_id
|
||||
where("updater_id = ?", user_id)
|
||||
else
|
||||
where("false")
|
||||
none
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class PostFlag < ApplicationRecord
|
||||
q = q.where.not(post_id: CurrentUser.user.posts)
|
||||
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
||||
else
|
||||
q = q.where("false")
|
||||
q = q.none
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,7 +86,7 @@ class PostFlag < ApplicationRecord
|
||||
q = q.where.not(post_id: CurrentUser.user.posts)
|
||||
q = q.where("creator_id = ?", flagger_id)
|
||||
else
|
||||
q = q.where("false")
|
||||
q = q.none
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user