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:
evazion
2022-04-18 00:14:19 -05:00
parent 5050ca527d
commit cd22c8eb1a

View File

@@ -23,6 +23,8 @@ class PostNavbarComponent < ApplicationComponent
end
def favgroups
return [] if current_user.is_anonymous? && favgroup_id.nil?
favgroups = FavoriteGroup.visible(current_user).for_post(post.id)
favgroups = favgroups.where(creator: current_user).or(favgroups.where(id: favgroup_id))
favgroups.sort_by do |favgroup|