Skip to content

A platform for community discussion. Free, open, simple.

FIX: Pull hotlinked images even when edited by system users (#9890)

David Taylor28f46c171c18
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index e7644e8ca84..a26fd0bf62a 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -152,7 +152,10 @@ module Jobs
changes = { raw: raw, edit_reason: I18n.t("upload.edit_reason") }
post.revise(Discourse.system_user, changes, bypass_bump: true, skip_staff_log: true)
elsif has_downloaded_image || has_new_large_image || has_new_broken_image
- post.trigger_post_process(bypass_bump: true)
+ post.trigger_post_process(
+ bypass_bump: true,
+ skip_pull_hotlinked_images: true # Avoid an infinite loop of job scheduling
+ )
end
end
diff --git a/app/models/post.rb b/app/models/post.rb
index e1a3a1f391e..7e92f0e5c48 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -748,11 +748,12 @@ class Post < ActiveRecord::Base
end
# Enqueue post processing for this post
- def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false)
+ def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false, skip_pull_hotlinked_images: false)
args = {
post_id: id,
bypass_bump: bypass_bump,
new_post: new_post,
+ skip_pull_hotlinked_images: skip_pull_hotlinked_images,
}
args[:image_sizes] = image_sizes if image_sizes.present?
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 258b791ddea..c2908a4fb88 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -663,12 +663,11 @@ class CookedPostProcessor
end
def pull_hotlinked_images
+ return if @opts[:skip_pull_hotlinked_images]
# have we enough disk space?
disable_if_low_on_disk_space # But still enqueue the job
# don't download remote images for posts that are more than n days old
return unless @post.created_at > (Date.today - SiteSetting.download_remote_images_max_days_old)
- # we only want to run the job whenever it's changed by a user
- return if @post.last_editor_id && @post.last_editor_id <= 0
# make sure no other job is scheduled
Jobs.cancel_scheduled_job(:pull_hotlinked_images, post_id: @post.id)
# schedule the job
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index b62350d2be5..efad82ca106 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1485,16 +1485,14 @@ describe CookedPostProcessor do
expect(SiteSetting.download_remote_images_to_local).to eq(false)
end
- context "and there is enough disk space" do
+ it "does not run when requested to skip" do
+ CookedPostProcessor.new(post, skip_pull_hotlinked_images: true).pull_hotlinked_images
+ expect(Jobs::PullHotlinkedImages.jobs.size).to eq(0)
+ end
+ context "and there is enough disk space" do
before { cpp.expects(:disable_if_low_on_disk_space) }
- it "does not run when the system user updated the post" do
- post.last_editor_id = Discourse.system_user.id
- Jobs.expects(:cancel_scheduled_job).never
- cpp.pull_hotlinked_images
- end
-
context "and the post has been updated by an actual user" do
before { post.id = 42 }