posts: eliminate unnecessary favgroup query on posts show page.
Eliminate a SQL query loading the post's favgroups if the current user is anonymous (and therefore can't have favgroups).
This commit is contained in:
@@ -23,6 +23,8 @@ class PostNavbarComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def favgroups
|
def favgroups
|
||||||
|
return [] if current_user.is_anonymous? && favgroup_id.nil?
|
||||||
|
|
||||||
favgroups = FavoriteGroup.visible(current_user).for_post(post.id)
|
favgroups = FavoriteGroup.visible(current_user).for_post(post.id)
|
||||||
favgroups = favgroups.where(creator: current_user).or(favgroups.where(id: favgroup_id))
|
favgroups = favgroups.where(creator: current_user).or(favgroups.where(id: favgroup_id))
|
||||||
favgroups.sort_by do |favgroup|
|
favgroups.sort_by do |favgroup|
|
||||||
|
|||||||
Reference in New Issue
Block a user