DEV: Add bucket folder path to inventory id

This commit is contained in:
Vinoth Kannan 2019-05-02 04:35:35 +05:30
parent 885f1e7e5f
commit 73418aaf73
2 changed files with 17 additions and 7 deletions

View File

@ -535,4 +535,4 @@ DEPENDENCIES
webpush
BUNDLED WITH
1.17.3
2.0.1

View File

@ -5,7 +5,7 @@ require "csv"
class S3Inventory
attr_reader :inventory_id, :model, :inventory_date
attr_reader :type, :model, :inventory_date
CSV_KEY_INDEX ||= 1
CSV_ETAG_INDEX ||= 2
@ -16,10 +16,10 @@ class S3Inventory
@s3_helper = s3_helper
if type == :upload
@inventory_id = "original"
@type = "original"
@model = Upload
elsif type == :optimized
@inventory_id = "optimized"
@type = "optimized"
@model = OptimizedImage
end
end
@ -30,13 +30,13 @@ class S3Inventory
return
end
DistributedMutex.synchronize("s3_inventory_list_missing_#{inventory_id}") do
DistributedMutex.synchronize("s3_inventory_list_missing_#{type}") do
download_inventory_files_to_tmp_directory
decompress_inventory_files
ActiveRecord::Base.transaction do
begin
table_name = "#{inventory_id}_inventory"
table_name = "#{type}_inventory"
connection = ActiveRecord::Base.connection.raw_connection
connection.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 S3Inventory
end
def inventory_configuration
filter_prefix = inventory_id
filter_prefix = type
filter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?
{
@ -204,6 +204,16 @@ class S3Inventory
log("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_arn
File.join(bucket_arn, inventory_path)
end