mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Backoff-retry for hotlinked image pull + some style fixes
This commit is contained in:
parent
b309deef11
commit
7da5d3fe78
@ -21,6 +21,7 @@ module Jobs
|
|||||||
return unless post.present?
|
return unless post.present?
|
||||||
|
|
||||||
raw = post.raw.dup
|
raw = post.raw.dup
|
||||||
|
start_raw = raw.dup
|
||||||
downloaded_urls = {}
|
downloaded_urls = {}
|
||||||
|
|
||||||
extract_images_from(post.cooked).each do |image|
|
extract_images_from(post.cooked).each do |image|
|
||||||
@ -28,9 +29,10 @@ module Jobs
|
|||||||
src = "http:" + src if src.start_with?("//")
|
src = "http:" + src if src.start_with?("//")
|
||||||
|
|
||||||
if is_valid_image_url(src)
|
if is_valid_image_url(src)
|
||||||
|
hotlinked = nil
|
||||||
begin
|
begin
|
||||||
# have we already downloaded that file?
|
# have we already downloaded that file?
|
||||||
if !downloaded_urls.include?(src)
|
unless downloaded_urls.include?(src)
|
||||||
begin
|
begin
|
||||||
hotlinked = FileHelper.download(src, @max_size, "discourse-hotlinked")
|
hotlinked = FileHelper.download(src, @max_size, "discourse-hotlinked")
|
||||||
rescue Discourse::InvalidParameters
|
rescue Discourse::InvalidParameters
|
||||||
@ -71,10 +73,15 @@ module Jobs
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: make sure the post hasn´t changed while we were downloading remote images
|
post.reload
|
||||||
if raw != post.raw
|
if start_raw != post.raw
|
||||||
|
# post was edited - start over (after 10 minutes)
|
||||||
|
backoff = args.fetch(:backoff, 1) + 1
|
||||||
|
delay = SiteSetting.ninja_edit_window * args[:backoff]
|
||||||
|
Jobs.enqueue_in(delay.seconds.to_i, :pull_hotlinked_images, args.merge!(backoff: backoff))
|
||||||
|
elsif raw != post.raw
|
||||||
options = { edit_reason: I18n.t("upload.edit_reason") }
|
options = { edit_reason: I18n.t("upload.edit_reason") }
|
||||||
options[:bypass_bump] = true if args[:bypass_bump] == true
|
options[:bypass_bump] = !!args[:bypass_bump]
|
||||||
post.revise(Discourse.system_user, raw, options)
|
post.revise(Discourse.system_user, raw, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user