Skip to content

Commit

Permalink
Protects against FileSets being added repeatedly to Work. (#1963)
Browse files Browse the repository at this point in the history
* Protects against Filesets being added repeatedly to Work.

* Lowers complexity.
  • Loading branch information
bwatson78 authored Sep 15, 2022
1 parent b638b18 commit fb12c70
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/jobs/associate_filesets_with_work_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class AssociateFilesetsWithWorkJob < Hyrax::ApplicationJob
include ::Hyrax::Lockable
queue_as :import

def perform(importer)
Expand Down Expand Up @@ -42,10 +43,21 @@ def process_file_sets(parents, file_set_entries)
file_sets = pull_file_sets(file_set_entries, p)
raise 'A CurateGenericWork and/or FileSet objects could not be found' unless work.present? && file_sets.present?

work.ordered_members += file_sets
work.save
associate_filesets_to_work(file_sets, work)
announce_filesets_attachement(file_sets)
end
end

file_sets.each { |fs| Hyrax.config.callback.run(:after_create_fileset, fs, ::User.find_by(uid: fs.depositor)) }
def associate_filesets_to_work(file_sets, work)
acquire_lock_for(work.id) do
unless file_sets&.map(&:id)&.all? { |id| work.reload.ordered_member_ids.include?(id) }
work.ordered_members += file_sets
work.save
end
end
end

def announce_filesets_attachement(file_sets)
file_sets.each { |fs| Hyrax.config.callback.run(:after_create_fileset, fs, ::User.find_by(uid: fs.depositor)) }
end
end

0 comments on commit fb12c70

Please sign in to comment.