Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-5578 Add a transaction to pseud image migration #5018

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions lib/tasks/after_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,26 @@ namespace :After do

Pseud.no_touching do
Pseud.find_in_batches.with_index do |batch, index|
batch.each do |pseud|
next if pseud.icon_file_name.blank?

image = pseud.icon_file_name
ext = File.extname(image)
image_original = "original#{ext}"

icon_url = if Rails.env.production?
"https://s3.amazonaws.com/otw-ao3-icons/icons/#{pseud.id}/#{image_original}"
else
"https://s3.amazonaws.com/otw-ao3-icons/staging/icons/#{pseud.id}/#{image_original}"
end
begin
pseud.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: pseud.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
ActiveRecord::Base.transaction do
batch.each do |pseud|
next if pseud.icon_file_name.blank?

image = pseud.icon_file_name
ext = File.extname(image)
image_original = "original#{ext}"

icon_url = if Rails.env.production?
"https://s3.amazonaws.com/otw-ao3-icons/icons/#{pseud.id}/#{image_original}"
else
"https://s3.amazonaws.com/otw-ao3-icons/staging/icons/#{pseud.id}/#{image_original}"
end
begin
pseud.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: pseud.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
end
end
end

Expand Down
Loading