From 61610a61fa1508015d1d81867a45ba2a59c624ec Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Jul 2024 19:06:46 +1000 Subject: [PATCH] FIX: disallow concurrent downloads of hotlinked images (#27676) --- app/jobs/regular/pull_hotlinked_images.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) 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?