Class: Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor
- Inherits:
-
CreateWithRemoteFilesActor
- Object
- AbstractActor
- CreateWithRemoteFilesActor
- Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor
- Defined in:
- app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb
Overview
When adding member FileSetBehaviors to a WorkBehavior, Hyrax saves and reloads the work for each new member FileSet. This can significantly slow down ingest for Works with many member FileSets. The saving and reloading happens in FileSetActor#attach_to_work.
This is a ‘swappable’ alternative approach. It will be of most value to Hyrax applications dealing with works with many filesets. Anecdotally, a 600 FileSet work can be processed in ~15 mins versus >3 hours with the standard approach.
The tradeoff is that the ordered members are now added in a single step after the creation of all the FileSets, thus introducing a slight risk of orphan filesets if the upload fails before the addition of the ordered members. This has not been observed in practice.
Swapping out the actors can be achieved thus:
In config/initializers/hyrax.rb
:
Hyrax::CurationConcern.actor_factory.swap(Hyrax::Actors::CreateWithRemoteFilesActor,
Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor)
Alternatively, in config/application.rb
:
config.to_prepare
Hyrax::CurationConcern.actor_factory.swap(Hyrax::Actors::CreateWithRemoteFilesActor,
Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor)
end
If there is a key :remote_files
in the attributes, it attaches the files at the specified URIs to the work. e.g.:
attributes[:remote_files] = filenames.map do |name|
{ url: "https://example.com/file/#{name}", file_name: name }
end
Browse everything may also return a local file. And although it’s in the url property, it may have spaces, and not be a valid URI.
Instance Attribute Summary collapse
-
#ordered_members ⇒ Object
readonly
Returns the value of attribute ordered_members.
Attributes inherited from AbstractActor
Instance Method Summary collapse
Methods inherited from CreateWithRemoteFilesActor
Methods inherited from AbstractActor
Constructor Details
This class inherits a constructor from Hyrax::Actors::AbstractActor
Instance Attribute Details
#ordered_members ⇒ Object (readonly)
Returns the value of attribute ordered_members.
41 42 43 |
# File 'app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb', line 41 def ordered_members @ordered_members end |
Instance Method Details
#attach_files(env, remote_files) ⇒ TrueClass
46 47 48 49 50 51 52 53 54 |
# File 'app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb', line 46 def attach_files(env, remote_files) @ordered_members = env.curation_concern.ordered_members.to_a ingest_remote_files_service_class.new(user: env.user, curation_concern: env.curation_concern, remote_files: remote_files, ordered_members: @ordered_members, ordered: true, file_set_actor_class: file_set_actor_class).attach! end |