Skip to content

Commit

Permalink
Avoid duplicate attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjaustin committed Jan 9, 2025
1 parent c820bfb commit 476bd02
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/tasks/after_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ namespace :After do
# Path example: staging/icons/108621/original.png
path_parts = object.key.split("/")
next unless path_parts[-1]&.include?("original")
next if ActiveStorage::Attachment.where(record_type: "Collection", record_id: path_parts[-2]).any?

collection_id = path_parts[-2]
old_icon = URI.open("https://s3.amazonaws.com/#{bucket_name}/#{object.key}")
Expand All @@ -358,6 +357,7 @@ namespace :After do

key = nil
ActiveRecord::Base.transaction do
ActiveStorage::Attachment.where(record_type: "Collection", record_id: path_parts[-2]).destroy_all
blob = ActiveStorage::Blob.create_before_direct_upload!(
filename: path_parts[-1],
byte_size: old_icon.size,
Expand Down Expand Up @@ -401,7 +401,6 @@ namespace :After do
# Path example: staging/icons/108621/original.png
path_parts = object.key.split("/")
next unless path_parts[-1]&.include?("original")
next if ActiveStorage::Attachment.where(record_type: "Pseud", record_id: path_parts[-2]).any?

pseud_id = path_parts[-2]
old_icon = URI.open("https://s3.amazonaws.com/#{bucket_name}/#{object.key}")
Expand All @@ -414,6 +413,7 @@ namespace :After do

key = nil
ActiveRecord::Base.transaction do
ActiveStorage::Attachment.where(record_type: "Pseud", record_id: path_parts[-2]).destroy_all
blob = ActiveStorage::Blob.create_before_direct_upload!(
filename: path_parts[-1],
byte_size: old_icon.size,
Expand Down Expand Up @@ -457,7 +457,6 @@ namespace :After do
# Path example: staging/icons/108621/original.png
path_parts = object.key.split("/")
next unless path_parts[-1]&.include?("original")
next if ActiveStorage::Attachment.where(record_type: "Skin", record_id: path_parts[-2]).any?

skin_id = path_parts[-2]
old_icon = URI.open("https://s3.amazonaws.com/#{bucket_name}/#{object.key}")
Expand All @@ -470,6 +469,7 @@ namespace :After do

key = nil
ActiveRecord::Base.transaction do
ActiveStorage::Attachment.where(record_type: "Skin", record_id: path_parts[-2]).destroy_all
blob = ActiveStorage::Blob.create_before_direct_upload!(
filename: path_parts[-1],
byte_size: old_icon.size,
Expand Down

0 comments on commit 476bd02

Please sign in to comment.