2022-04-12 12:26:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2022-09-29 07:24:33 +08:00
|
|
|
# Sometimes we need to update a _lot_ of ACLs on S3 (such as when secure uploads
|
2022-04-12 12:26:42 +08:00
|
|
|
# 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)
|
|
|
|
|
2024-07-01 13:32:30 +08:00
|
|
|
# NOTE: These log messages are set to warn to ensure this is working
|
|
|
|
# as intended in initial production trials, this will need to be set to debug
|
2022-04-12 12:26:42 +08:00
|
|
|
# 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|
|
2022-05-23 11:14:11 +08:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
)
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
|
|
|
end
|
2022-05-23 11:14:11 +08:00
|
|
|
end
|
2022-04-12 12:26:42 +08:00
|
|
|
Rails.logger.warn(
|
2023-12-07 06:25:00 +08:00
|
|
|
"Completed syncing ACL for upload ids in #{time}. IDs: #{args[:upload_ids].join(", ")}",
|
2023-01-09 20:20:10 +08:00
|
|
|
)
|
2022-04-12 12:26:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|