posts/show: avoid extra queries when rendering pool list.
This commit is contained in:
@@ -39,9 +39,8 @@ class Pool < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def selected_first(current_pool_id)
|
def selected_first(current_pool_id)
|
||||||
return where("true") if current_pool_id.blank?
|
return all if current_pool_id.blank?
|
||||||
current_pool_id = current_pool_id.to_i
|
reorder(Arel.sql("(case pools.id when #{current_pool_id.to_i} then 0 else 1 end), pools.name"))
|
||||||
reorder(Arel.sql("(case pools.id when #{current_pool_id} then 0 else 1 end), pools.name"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_matches(name)
|
def name_matches(name)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<%= render "posts/partials/show/search_seq", :post => post %>
|
<%= render "posts/partials/show/search_seq", :post => post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if post.pools.undeleted.any? %>
|
<% if post.pools.undeleted.present? %>
|
||||||
<%= render "posts/partials/show/pool_list", post: post, pools: post.pools.undeleted.selected_first(params[:pool_id]) %>
|
<%= render "posts/partials/show/pool_list", post: post, pools: post.pools.undeleted.selected_first(params[:pool_id]) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user