From bfa2ae3f56b9c561f56fccab536b4f77d60ec979 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 23 Jul 2024 10:26:38 -0600 Subject: [PATCH 1/4] Bullet fixes for `/super_admin/api_clients` --- app/views/super_admin/api_clients/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/super_admin/api_clients/_form.html.erb b/app/views/super_admin/api_clients/_form.html.erb index 02d33f2116..4d22402d50 100644 --- a/app/views/super_admin/api_clients/_form.html.erb +++ b/app/views/super_admin/api_clients/_form.html.erb @@ -1,7 +1,7 @@ <% url = @api_client.new_record? ? super_admin_api_clients_path : super_admin_api_client_path(@api_client) method = @api_client.new_record? ? :post : :put -orgs = Org.where(is_other: false) +orgs = Org.where(is_other: false).includes(identifiers: :identifier_scheme) %> <%= form_for @api_client, url: url, method: method, From 935433c32712b915e0e84ae702e2d55b76f9b1c8 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 23 Jul 2024 11:18:42 -0600 Subject: [PATCH 2/4] Bullet fixes for `/public_plans` --- app/controllers/public_pages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/public_pages_controller.rb b/app/controllers/public_pages_controller.rb index 99fd1dcd1f..1b5d9cff93 100644 --- a/app/controllers/public_pages_controller.rb +++ b/app/controllers/public_pages_controller.rb @@ -85,7 +85,7 @@ def template_export # GET /plans_index # ------------------------------------------------------------------------------------ def plan_index - @plans = Plan.publicly_visible.includes(:template) + @plans = Plan.publicly_visible.includes(:template, roles: { user: :org }) render 'plan_index', locals: { query_params: { page: paginable_params.fetch(:page, 1), From a079c576fcbd74324dfbf3e2d18bf33e37587635 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 23 Jul 2024 11:05:23 -0600 Subject: [PATCH 3/4] Bullet fixes for `/org_admin/plans` (superuser) app/views/org_admin/plans/index.html.erb: - .length loads the records into memory. Because we are eager-loading other tables (see code changes in app/controllers/org_admin/plans_controller.rb), this was triggering a "AVOID eager loading detected" Bullet warning. Because we are in fact making use of these related tables further in the code, the warnings themselves appear to be false-positives. However, the change to this file manages to suppresses the Bullet warnings, and is still very fast. --- app/controllers/org_admin/plans_controller.rb | 2 +- app/views/org_admin/plans/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/org_admin/plans_controller.rb b/app/controllers/org_admin/plans_controller.rb index f673fc18cf..98a0fa7c8b 100644 --- a/app/controllers/org_admin/plans_controller.rb +++ b/app/controllers/org_admin/plans_controller.rb @@ -17,7 +17,7 @@ def index @super_admin = current_user.can_super_admin? @clicked_through = params[:click_through].present? - @plans = @super_admin ? Plan.all.page(1) : current_user.org.org_admin_plans.page(1) + @plans = @super_admin ? Plan.all.page(1).includes(:template, roles: { user: :org }) : current_user.org.org_admin_plans.page(1) end # rubocop:enable Metrics/AbcSize diff --git a/app/views/org_admin/plans/index.html.erb b/app/views/org_admin/plans/index.html.erb index 2689adab13..e51c845cfd 100644 --- a/app/views/org_admin/plans/index.html.erb +++ b/app/views/org_admin/plans/index.html.erb @@ -34,7 +34,7 @@ <% end %> - <% if @plans.length > 0 %> + <% if @plans.any? %> <% unless @super_admin %> <%= link_to sanitize(_('Download plans (new window)%{open_in_new_window_text}') % { open_in_new_window_text: _('Opens in new window') }, From a07d3442bbba3aeee336d29a49d024c396ff02b1 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 23 Jul 2024 11:26:35 -0600 Subject: [PATCH 4/4] Make Rubocop happy --- app/controllers/org_admin/plans_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/org_admin/plans_controller.rb b/app/controllers/org_admin/plans_controller.rb index 98a0fa7c8b..64e16b59d0 100644 --- a/app/controllers/org_admin/plans_controller.rb +++ b/app/controllers/org_admin/plans_controller.rb @@ -17,7 +17,11 @@ def index @super_admin = current_user.can_super_admin? @clicked_through = params[:click_through].present? - @plans = @super_admin ? Plan.all.page(1).includes(:template, roles: { user: :org }) : current_user.org.org_admin_plans.page(1) + @plans = if @super_admin + Plan.all.page(1).includes(:template, roles: { user: :org }) + else + current_user.org.org_admin_plans.page(1) + end end # rubocop:enable Metrics/AbcSize