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:
evazion
2018-08-23 15:21:51 -05:00
parent db23e06a4f
commit 85ae2cda0d
4 changed files with 5 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ module PostSets
query
end
rescue ::Post::SearchError
::Post.where("false")
::Post.none
end
def presenter

View File

@@ -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)

View File

@@ -22,7 +22,7 @@ class PostArchive < ApplicationRecord
if user_id
where("updater_id = ?", user_id)
else
where("false")
none
end
end

View File

@@ -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