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