Skip to content

Commit

Permalink
Extract common eager loading parameters into Class
Browse files Browse the repository at this point in the history
This helps keep the duplication down.
  • Loading branch information
mamhoff committed Apr 27, 2022
1 parent 5b61e8b commit 1ac0d43
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
15 changes: 1 addition & 14 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,20 +404,7 @@ def set_preview_mode
end

def page_includes
{
:tags,
language: :site,
draft_version: {
elements: [
:page,
:touchable_pages,
{
ingredients: :related_object,
contents: :essence,
},
],
},
}
Alchemy::EagerLoading.page_includes(version: :draft_version)
end
end
end
Expand Down
15 changes: 1 addition & 14 deletions app/controllers/alchemy/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,7 @@ def page_not_found!
end

def page_includes
{
:tags,
language: :site,
public_version: {
elements: [
:page,
:touchable_pages,
{
ingredients: :related_object,
contents: :essence,
},
],
},
}
Alchemy::EagerLoading.page_includes(version: :public_version)
end
end
end
13 changes: 1 addition & 12 deletions app/jobs/alchemy/publish_page_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,7 @@ class PublishPageJob < BaseJob

def perform(page_id, public_on:)
page = Alchemy::Page.includes(
:tags,
language: :site,
draft_version: {
elements: [
:page,
:touchable_pages,
{
ingredients: :related_object,
contents: :essence,
},
],
},
Alchemy::EagerLoading.page_includes(version: :draft_version)
).find(page_id)
Alchemy::Page::Publisher.new(page).publish!(public_on: public_on)
end
Expand Down
24 changes: 24 additions & 0 deletions app/models/alchemy/eager_loading.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Alchemy
class EagerLoading
class << self
def page_includes(version: :public_version)
{
:tags,
language: :site,
version => {
elements: [
:page,
:touchable_pages,
{
ingredients: :related_object,
contents: :essence,
},
],
},
}
end
end
end
end

0 comments on commit 1ac0d43

Please sign in to comment.