posts/show: avoid extra queries when rendering pool list.

This commit is contained in:
evazion
2019-09-06 23:23:01 -05:00
parent 37e48844fd
commit 57a61ca586
2 changed files with 3 additions and 4 deletions

View File

@@ -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)

View File

@@ -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 %>