From dc424e9fef957988aea9701f0373eedb14a72ede Mon Sep 17 00:00:00 2001 From: Alex Dolski Date: Fri, 1 Mar 2024 16:09:29 -0600 Subject: [PATCH] all_files() uses ItemRelation.each_id_in_batches() to improve performance in large collections --- app/controllers/collections_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index dd18a7e3..12994063 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -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,