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

This commit is contained in:
Sam 2024-07-02 19:06:46 +10:00 committed by GitHub
parent 7c26d5d084
commit 61610a61fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -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?