Skip to content

Commit

Permalink
Eager load relations in elements trash
Browse files Browse the repository at this point in the history
This should speed up large trashes.
  • Loading branch information
tvdeyen committed Feb 24, 2020
1 parent 6e5180d commit 4d93f2c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/controllers/alchemy/admin/trash_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TrashController < Alchemy::Admin::BaseController
authorize_resource class: false

def index
@elements = Element.trashed
@elements = Element.trashed.includes(*element_includes)
@page = Page.find(params[:page_id])
@allowed_elements = @page.available_element_definitions
end
Expand All @@ -18,6 +18,25 @@ def clear
@elements = Element.trashed
@elements.map(&:destroy)
end

private

def element_includes
[
{
contents: {
essence: :ingredient_association
},
all_nested_elements: [
{
contents: {
essence: :ingredient_association
}
}
]
}
]
end
end
end
end

0 comments on commit 4d93f2c

Please sign in to comment.