From cd22c8eb1a325ebb882264e7779fc37f86703880 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 18 Apr 2022 00:14:19 -0500 Subject: [PATCH] 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). --- app/components/post_navbar_component.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/components/post_navbar_component.rb b/app/components/post_navbar_component.rb index d1b6fccd2..979a4d4c3 100644 --- a/app/components/post_navbar_component.rb +++ b/app/components/post_navbar_component.rb @@ -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|