A platform for community discussion. Free, open, simple.
DEV: Add bucket folder path to inventory id
Vinoth Kannan73418aaf73cf
diff --git a/Gemfile.lock b/Gemfile.lockindex f826683561b..9576cb2b432 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -535,4 +535,4 @@ DEPENDENCIESwebpushBUNDLED WITH- 1.17.3+ 2.0.1diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rbindex 8ec4ff5f451..486d49244ea 100644--- a/lib/s3_inventory.rb+++ b/lib/s3_inventory.rb@@ -5,7 +5,7 @@ require "csv"class S3Inventory- attr_reader :inventory_id, :model, :inventory_date+ attr_reader :type, :model, :inventory_dateCSV_KEY_INDEX ||= 1CSV_ETAG_INDEX ||= 2@@ -16,10 +16,10 @@ class S3Inventory@s3_helper = s3_helperif type == :upload- @inventory_id = "original"+ @type = "original"@model = Uploadelsif type == :optimized- @inventory_id = "optimized"+ @type = "optimized"@model = OptimizedImageendend@@ -30,13 +30,13 @@ class S3Inventoryreturnend- DistributedMutex.synchronize("s3_inventory_list_missing_#{inventory_id}") do+ DistributedMutex.synchronize("s3_inventory_list_missing_#{type}") dodownload_inventory_files_to_tmp_directorydecompress_inventory_filesActiveRecord::Base.transaction dobegin- table_name = "#{inventory_id}_inventory"+ table_name = "#{type}_inventory"connection = ActiveRecord::Base.connection.raw_connectionconnection.exec("CREATE TEMP TABLE #{table_name}(key text UNIQUE, etag text, PRIMARY KEY(etag, key))")connection.copy_data("COPY #{table_name} FROM STDIN CSV") do@@ -157,7 +157,7 @@ class S3Inventoryenddef inventory_configuration- filter_prefix = inventory_id+ filter_prefix = typefilter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?{@@ -204,6 +204,16 @@ class S3Inventorylog("Failed to list inventory from S3", e)end+ def inventory_id+ @inventory_id ||= begin+ if bucket_folder_path.present?+ "#{bucket_folder_path}-#{type}"+ else+ type+ end+ end+ end+def inventory_path_arnFile.join(bucket_arn, inventory_path)end