From aa45abd9f6644dedb2eb7e03af255cfce61ce288 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 14 Jun 2022 10:29:12 +0200 Subject: [PATCH] Remove N+1 from admin users table We preload users orders, but call count in the template. This will always query the database. Using none? uses the preloaded collection instead. --- backend/app/views/spree/admin/users/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/views/spree/admin/users/index.html.erb b/backend/app/views/spree/admin/users/index.html.erb index 81d82443b89..244f27dd0b9 100644 --- a/backend/app/views/spree/admin/users/index.html.erb +++ b/backend/app/views/spree/admin/users/index.html.erb @@ -89,7 +89,7 @@ <% if can?(:edit, user) %> <%= link_to_edit user, no_text: true, url: spree.admin_user_path(user) %> <% end %> - <% if can?(:destroy, user) && user.orders.count.zero? %> + <% if can?(:destroy, user) && user.orders.none? %> <%= link_to_delete user, no_text: true, url: spree.admin_user_path(user) %> <% end %>