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 ActiveStorage copy script performance fixes #5015

Merged
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
105 changes: 60 additions & 45 deletions lib/tasks/after_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,27 @@ namespace :After do

return unless Rails.env.staging? || Rails.env.production?

Collection.where.not(icon_file_name: nil).find_each do |collection|
image = collection.icon_file_name
ext = File.extname(image)
image_original = "original#{ext}"

# Collection icons are co-mingled in production and staging...
icon_url = "https://s3.amazonaws.com/otw-ao3-icons/collections/icons/#{collection.id}/#{image_original}"
begin
collection.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: collection.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
Collection.find_in_batches.with_index do |batch, index|
batch.each do |collection|
next if collection.icon_file_name.blank?

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

# Collection icons are co-mingled in production and staging...
icon_url = "https://s3.amazonaws.com/otw-ao3-icons/collections/icons/#{collection.id}/#{image_original}"
begin
collection.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: collection.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
end
end

puts "Finished up to ID #{collection.id}" if collection.id.modulo(100).zero?
puts "Finished batch #{index + 1}" && $stdout.flush
sleep 10
end
end

Expand All @@ -354,25 +359,30 @@ namespace :After do

return unless Rails.env.staging? || Rails.env.production?

Pseud.where.not(icon_file_name: nil).find_each do |pseud|
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}"
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}"
end
end

puts "Finished up to ID #{pseud.id}" if pseud.id.modulo(100).zero?
puts "Finished batch #{index + 1}" && $stdout.flush
sleep 10
end
end

Expand All @@ -382,22 +392,27 @@ namespace :After do

return unless Rails.env.staging? || Rails.env.production?

Skin.where.not(icon_file_name: nil).find_each do |skin|
image = skin.icon_file_name
ext = File.extname(image)
image_original = "original#{ext}"

# Skin icons are co-mingled in production and staging...
icon_url = "https://s3.amazonaws.com/otw-ao3-icons/skins/icons/#{skin.id}/#{image_original}"
begin
skin.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: skin.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
Skin.find_in_batches.with_index do |batch, index|
batch.each do |skin|
next if skin.icon_file_name.blank?

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

# Skin icons are co-mingled in production and staging...
icon_url = "https://s3.amazonaws.com/otw-ao3-icons/skins/icons/#{skin.id}/#{image_original}"
begin
skin.icon.attach(io: URI.parse(icon_url).open,
filename: image_original,
content_type: skin.icon_content_type)
rescue StandardError => e
puts "Error '#{e}' copying #{icon_url}"
end
end

puts "Finished up to ID #{skin.id}" if skin.id.modulo(100).zero?
puts "Finished batch #{index + 1}" && $stdout.flush
sleep 10
end
end
# This is the end that you have to put new tasks above.
Expand Down
Loading