PERF: Update post uploads secure status in a job (#13459)

When secure uploads are enabled, editing a post with many uploads can
cause a timeout because the store has to be contacted for each upload.
This commit is contained in:
Bianca Nenciu 2021-06-21 19:15:24 +03:00 committed by GitHub
parent 15aa213a61
commit d1b2e9db3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
module Jobs
class UpdatePostUploadsSecureStatus < ::Jobs::Base
def execute(args)
post = Post.find_by(id: args[:post_id])
return if post.blank?
post.uploads.each do |upload|
upload.update_secure_status(source: args[:source])
end
end
end
end

View File

@ -960,7 +960,7 @@ class Post < ActiveRecord::Base
def update_uploads_secure_status(source:)
if Discourse.store.external?
self.uploads.each { |upload| upload.update_secure_status(source: source) }
Jobs.enqueue(:update_post_uploads_secure_status, post_id: self.id, source: source)
end
end

View File

@ -1119,6 +1119,7 @@ describe PostRevisor do
context "secure media uploads" do
let!(:image5) { Fabricate(:secure_upload) }
before do
Jobs.run_immediately!
setup_s3
SiteSetting.authorized_extensions = "png|jpg|gif|mp4"
SiteSetting.secure_media = true

View File

@ -1481,6 +1481,8 @@ describe Post do
end
before do
Jobs.run_immediately!
setup_s3
SiteSetting.authorized_extensions = "pdf|png|jpg|csv"
SiteSetting.secure_media = true