mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 05:09:46 +08:00
DEV: Add bucket folder path to inventory id
This commit is contained in:
parent
885f1e7e5f
commit
73418aaf73
|
@ -535,4 +535,4 @@ DEPENDENCIES
|
||||||
webpush
|
webpush
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.17.3
|
2.0.1
|
||||||
|
|
|
@ -5,7 +5,7 @@ require "csv"
|
||||||
|
|
||||||
class S3Inventory
|
class S3Inventory
|
||||||
|
|
||||||
attr_reader :inventory_id, :model, :inventory_date
|
attr_reader :type, :model, :inventory_date
|
||||||
|
|
||||||
CSV_KEY_INDEX ||= 1
|
CSV_KEY_INDEX ||= 1
|
||||||
CSV_ETAG_INDEX ||= 2
|
CSV_ETAG_INDEX ||= 2
|
||||||
|
@ -16,10 +16,10 @@ class S3Inventory
|
||||||
@s3_helper = s3_helper
|
@s3_helper = s3_helper
|
||||||
|
|
||||||
if type == :upload
|
if type == :upload
|
||||||
@inventory_id = "original"
|
@type = "original"
|
||||||
@model = Upload
|
@model = Upload
|
||||||
elsif type == :optimized
|
elsif type == :optimized
|
||||||
@inventory_id = "optimized"
|
@type = "optimized"
|
||||||
@model = OptimizedImage
|
@model = OptimizedImage
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,13 +30,13 @@ class S3Inventory
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
DistributedMutex.synchronize("s3_inventory_list_missing_#{inventory_id}") do
|
DistributedMutex.synchronize("s3_inventory_list_missing_#{type}") do
|
||||||
download_inventory_files_to_tmp_directory
|
download_inventory_files_to_tmp_directory
|
||||||
decompress_inventory_files
|
decompress_inventory_files
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
table_name = "#{inventory_id}_inventory"
|
table_name = "#{type}_inventory"
|
||||||
connection = ActiveRecord::Base.connection.raw_connection
|
connection = ActiveRecord::Base.connection.raw_connection
|
||||||
connection.exec("CREATE TEMP TABLE #{table_name}(key text UNIQUE, etag text, PRIMARY KEY(etag, key))")
|
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
|
connection.copy_data("COPY #{table_name} FROM STDIN CSV") do
|
||||||
|
@ -157,7 +157,7 @@ class S3Inventory
|
||||||
end
|
end
|
||||||
|
|
||||||
def inventory_configuration
|
def inventory_configuration
|
||||||
filter_prefix = inventory_id
|
filter_prefix = type
|
||||||
filter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?
|
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)
|
log("Failed to list inventory from S3", e)
|
||||||
end
|
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
|
def inventory_path_arn
|
||||||
File.join(bucket_arn, inventory_path)
|
File.join(bucket_arn, inventory_path)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user