PERF: no need to select entire group just to find name

PERF: no need to select entire group just to find name

Note, this is a very good candidate for some cache longer term to cut the query out

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 22c24fa..0f9c896 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -125,7 +125,9 @@ module ApplicationHelper
       result << "category-#{@category.url.sub(/^\/c\//, '').gsub(/\//, '-')}"
     end
 
-    if current_user.present? && primary_group_name = current_user.primary_group&.name
+    if current_user.present? &&
+        current_user.primary_group_id &&
+        primary_group_name = Group.where(id: current_user.primary_group_id).pluck(:name).first
       result << "primary-group-#{primary_group_name.downcase}"
     end

GitHub sha: 5a8451bf

1 Like