Skip to content

Commit

Permalink
Manually preload the :translations to avoid the N+1 queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkone committed May 2, 2012
1 parent 332b512 commit 3e2b3ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pages/app/helpers/refinery/admin/pages_helper.rb
@@ -1,6 +1,18 @@
module Refinery
module Admin
module PagesHelper
def parent_id_nested_set_options(current_page)
all_pages = []
options = nested_set_options(::Refinery::Page, current_page) do |page|
all_pages << page
page
end
# page.title needs the :translations association, doing something like
# nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work
ActiveRecord::Associations::Preloader.new(all_pages, :translations).run
options.map! {|page, id| ["#{'-' * page.level} #{page.title}", id]}
options
end
end
end
end
Expand Up @@ -18,8 +18,7 @@
<%= f.label :parent_id, t('.parent_page') %>
<%= refinery_help_tag t('.parent_page_help') %>
</span>
<%= f.select :parent_id, nested_set_options(::Refinery::Page, @page) {|i| "#{'-' * i.level} #{i.title}" },
:include_blank => true %>
<%= f.select :parent_id, parent_id_nested_set_options(@page), :include_blank => true %>
</div>
<% if Refinery::Pages.use_layout_templates %>
<div class='field'>
Expand Down

0 comments on commit 3e2b3ad

Please sign in to comment.