From 476bd029e0e01cfad64d7767262e3352f3bc1d73 Mon Sep 17 00:00:00 2001 From: Brian Austin Date: Wed, 8 Jan 2025 20:37:33 -0500 Subject: [PATCH] Avoid duplicate attachments --- lib/tasks/after_tasks.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/after_tasks.rake b/lib/tasks/after_tasks.rake index 597a0dc59f..427c15f131 100644 --- a/lib/tasks/after_tasks.rake +++ b/lib/tasks/after_tasks.rake @@ -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}") @@ -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, @@ -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}") @@ -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, @@ -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}") @@ -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,