Verified Commit b356fb26 authored by Tam Le's avatar Tam Le
Browse files

Remove n+1 query on 'assigned' view column in SP#index

parent 653719f9
No related merge requests found
Showing with 5 additions and 1 deletion
+5 -1
......@@ -25,6 +25,10 @@ class ServicePacksController < ApplicationController
wildcard_sanitized_name = "%#{ActiveRecord::Base.send(:sanitize_sql_like, params[:name], -'!')}%"
@service_packs = @service_packs.where(-"name LIKE ?", wildcard_sanitized_name)
end
# to remove N+1 query 'EXISTS'
for_added_column = Assign.active.where(-'service_pack_id = service_packs.id').to_sql
@service_packs = @service_packs.select(-'service_packs.*',
"(CASE WHEN EXISTS (#{for_added_column}) THEN 1 ELSE 0 END) AS assigned")
end
def new
......
......@@ -67,7 +67,7 @@
<td><%= sp.expired_date %></td>
<td><%= sp.threshold1 %></td>
<td><%= sp.threshold2 %></td>
<td><%= (sp.assigned? ? -'&#x2714' : -'').html_safe %></td>
<td><%= (sp.assigned == 1 ? -'&#x2714' : -'').html_safe %></td>
</tr>
<% end %>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment