Skip to content

Commit

Permalink
Deprecate passing a Page into PublishPageJob
Browse files Browse the repository at this point in the history
Passing an page "object" here through `GlobalID` and then reloading will
lead to double page loads.
  • Loading branch information
mamhoff committed Apr 27, 2022
1 parent c22e840 commit ac8555f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/jobs/alchemy/publish_page_job.rb
Expand Up @@ -4,15 +4,15 @@ module Alchemy
class PublishPageJob < BaseJob
queue_as :default

def perform(page, public_on:)
def perform(page_id, public_on:)
page = Alchemy::Page.includes(
draft_version: {
elements: [
{ ingredients: :related_object },
{ contents: :essence },
],
},
).find(page.id)
).find(page_id)
Alchemy::Page::Publisher.new(page).publish!(public_on: public_on)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/page.rb
Expand Up @@ -465,7 +465,7 @@ def copy_children_to(new_parent)
#
def publish!(current_time = Time.current)
update(published_at: current_time)
PublishPageJob.perform_later(self, public_on: current_time)
PublishPageJob.perform_later(id, public_on: current_time)
end

# Sets the public_on date on the published version
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/alchemy/publish_page_job_spec.rb
Expand Up @@ -9,15 +9,15 @@

it "enqueues job" do
expect {
described_class.perform_later(page, public_on: public_on)
described_class.perform_later(page.id, public_on: public_on)
}.to have_enqueued_job
end

it "calls the page publisher" do
expect_any_instance_of(Alchemy::Page::Publisher).to receive(:publish!).with(
public_on: public_on,
)
described_class.new.perform(page, public_on: public_on)
described_class.new.perform(page.id, public_on: public_on)
end
end
end

0 comments on commit ac8555f

Please sign in to comment.