Skip to content

Commit

Permalink
all_files() uses ItemRelation.each_id_in_batches() to improve perform…
Browse files Browse the repository at this point in the history
…ance in large collections
  • Loading branch information
Alex Dolski committed Mar 1, 2024
1 parent 467e48e commit dc424e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def all_files
respond_to do |format|
format.zip do
collection_ids = [@collection.id] + @collection.all_child_ids
item_ids = policy_scope(Item.search.filter(Item::IndexFields::COLLECTIONS, collection_ids),
policy_scope_class: ItemPolicy::Scope).to_id_a
item_ids = []
policy_scope(Item.search.filter(Item::IndexFields::COLLECTIONS, collection_ids),
policy_scope_class: ItemPolicy::Scope).each_id_in_batches do |result|
item_ids << result[:id]
end
if item_ids.any?
download = Download.create!(institution: @collection.institution,
ip_address: request.remote_ip)
task = Task.create!(name: ZipItemsJob.to_s)
ZipItemsJob.perform_later(item_ids: item_ids.map{ |h| h[:id] },
ZipItemsJob.perform_later(item_ids: item_ids,
metadata_profile: @collection.institution.default_metadata_profile,
download: download,
user: current_user,
Expand Down

0 comments on commit dc424e9

Please sign in to comment.