mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 13:03:39 +08:00
8ebd5edd1e
This commit renames all secure_media related settings to secure_uploads_* along with the associated functionality. This is being done because "media" does not really cover it, we aren't just doing this for images and videos etc. but for all uploads in the site. Additionally, in future we want to secure more types of uploads, and enable a kind of "mixed mode" where some uploads are secure and some are not, so keeping media in the name is just confusing. This also keeps compatibility with the `secure-media-uploads` path, and changes new secure URLs to be `secure-uploads`. Deprecated settings: * secure_media -> secure_uploads * secure_media_allow_embed_images_in_emails -> secure_uploads_allow_embed_images_in_emails * secure_media_max_email_embed_image_size_kb -> secure_uploads_max_email_embed_image_size_kb
40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
# Sometimes we need to update a _lot_ of ACLs on S3 (such as when secure uploads
|
|
# is enabled), and since it takes ~1s per upload to update the ACL, this is
|
|
# best spread out over many jobs instead of having to do the whole thing serially.
|
|
class SyncAclsForUploads < ::Jobs::Base
|
|
def execute(args)
|
|
return if !Discourse.store.external?
|
|
return if !args.key?(:upload_ids)
|
|
|
|
# TODO (martin) Change the logging here to debug after acl_stale implemented.
|
|
#
|
|
# Note...these log messages are set to warn to ensure this is working
|
|
# as intended in initial production trials, this will be set to debug
|
|
# after an acl_stale column is added to uploads.
|
|
time = Benchmark.measure do
|
|
Rails.logger.warn("Syncing ACL for upload ids: #{args[:upload_ids].join(", ")}")
|
|
Upload.includes(:optimized_images).where(id: args[:upload_ids]).find_in_batches do |uploads|
|
|
uploads.each do |upload|
|
|
begin
|
|
Discourse.store.update_upload_ACL(upload, optimized_images_preloaded: true)
|
|
rescue => err
|
|
Discourse.warn_exception(
|
|
err,
|
|
message: "Failed to update upload ACL",
|
|
env: {
|
|
upload_id: upload.id,
|
|
filename: upload.original_filename
|
|
}
|
|
)
|
|
end
|
|
end
|
|
end
|
|
Rails.logger.warn("Completed syncing ACL for upload ids in #{time.to_s}. IDs: #{args[:upload_ids].join(", ")}")
|
|
end
|
|
end
|
|
end
|
|
end
|