Skip to content

Commit

Permalink
Remove N+1 from admin users table
Browse files Browse the repository at this point in the history
We preload users orders, but call count in the template.
This will always query the database. Using none? uses
the preloaded collection instead.
  • Loading branch information
tvdeyen committed Jun 21, 2022
1 parent 9c70ee2 commit aa45abd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</td>
Expand Down

0 comments on commit aa45abd

Please sign in to comment.