mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Pull hotlinked images even when edited by system users (#9890)
Previously the pull hotlinked images job was skipped after system edits. This ensured that we never had an infinite loop of system-edit/pull-hotlinked/system-edit/pull-hotlinked etc. A side effect was that edits made by system for any other reason (e.g. API, removing full quotes) would prevent pulling hotlinked images. This commit removes the system edit check, and replaces it with another method to avoid an infinite job scheduling loop.
This commit is contained in:
parent
d29d69e10d
commit
28f46c171c
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1485,16 +1485,14 @@ describe CookedPostProcessor do
|
|||
expect(SiteSetting.download_remote_images_to_local).to eq(false)
|
||||
end
|
||||
|
||||
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 }
|
||||
|
|
Loading…
Reference in New Issue
Block a user