Skip to content

Commit

Permalink
S3 key already contains the DOI
Browse files Browse the repository at this point in the history
Lets utilize the key instead of the file name.  This stops an infinite loop from accuring in tests and for S3 files to not get added repeatedly when s3 is queried.
See https://pdc-describe-staging.princeton.edu/describe/works/75 for an example of a work where the files got added each time the work was saved
  • Loading branch information
carolyncole committed Sep 27, 2022
1 parent 3f66d7f commit e6247b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,8 @@ def update_ark_information
end

def generate_attachment_key(attachment)
key_base = "#{doi}/#{id}"

attachment_filename = attachment.filename.to_s
attachment_key = [key_base, attachment_filename].join("/")
attachment_key = attachment.key

attachment_ext = File.extname(attachment_filename)
attachment_query = attachment_key.gsub(attachment_ext, "")
Expand Down Expand Up @@ -636,10 +634,10 @@ def s3_resources
alias pre_curation_s3_resources s3_resources

def s3_object_persisted?(s3_file)
uploads_filenames = uploads.map(&:filename)
uploads_keys = uploads.map(&:key)

persisted_filenames = uploads_filenames.select { |filename| filename.to_s == s3_file.filename }
!persisted_filenames.empty?
persisted_keyss = uploads_keys.select { |key| key == s3_file.key }
!persisted_keyss.empty?
end

def add_pre_curation_s3_object(s3_file)
Expand Down
6 changes: 4 additions & 2 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,15 @@
let(:s3_query_service_double) { instance_double(S3QueryService) }
let(:file1) do
S3File.new(
filename: "SCoData_combined_v1_2020-07_README.txt",
filename: "#{work.doi}/#{work.id}/SCoData_combined_v1_2020-07_README.txt",
last_modified: Time.parse("2022-04-21T18:29:40.000Z"),
size: 10_759,
checksum: "abc123"
)
end
let(:file2) do
S3File.new(
filename: "SCoData_combined_v1_2020-07_datapackage.json",
filename: "#{work.doi}/#{work.id}/SCoData_combined_v1_2020-07_datapackage.json",
last_modified: Time.parse("2022-04-21T18:30:07.000Z"),
size: 12_739,
checksum: "abc567"
Expand Down Expand Up @@ -628,6 +628,8 @@
expect(work.pre_curation_uploads.first.key).to eq("#{work.doi}/#{work.id}/SCoData_combined_v1_2020-07_README.txt")
expect(work.pre_curation_uploads.last).to be_a(ActiveStorage::Attachment)
expect(work.pre_curation_uploads.last.key).to eq("#{work.doi}/#{work.id}/SCoData_combined_v1_2020-07_datapackage.json")
work.valid?
expect(work.pre_curation_uploads.length).to eq(2)
end

context "a blob already exists for one of the files" do
Expand Down

0 comments on commit e6247b7

Please sign in to comment.