Skip to content

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

FIX: disallow concurrent downloads of hotlinked images (#27676)

Sam61610a61fa15
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 19e216f22e6..8baf5d35e30 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -14,6 +14,17 @@ module Jobs
@post_id = args[:post_id]
raise Discourse::InvalidParameters.new(:post_id) if @post_id.blank?
+ # in test we have no choice cause we don't want to cause a deadlock
+ if Jobs.run_immediately?
+ pull_hotlinked_images
+ else
+ DistributedMutex.synchronize("pull_hotlinked_images_#{@post_id}", validity: 2.minutes) do
+ pull_hotlinked_images
+ end
+ end
+ end
+
+ def pull_hotlinked_images
post = Post.find_by(id: @post_id)
return if post.nil? || post.topic.nil?