From ebea606382ffdbcb0eb6687a0677874faa1e1aed Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 11 Oct 2017 10:12:12 -0400 Subject: [PATCH] Use uncached only on the ActiveFedora find --- .rubocop_fixme.yml | 1 + .../hyrax/adapters/nesting_index_adapter.rb | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.rubocop_fixme.yml b/.rubocop_fixme.yml index 7ddf4953cd..fb52bcc4db 100644 --- a/.rubocop_fixme.yml +++ b/.rubocop_fixme.yml @@ -29,6 +29,7 @@ Metrics/ModuleLength: - 'app/models/concerns/hyrax/ability.rb' - 'app/services/hyrax/workflow/permission_query.rb' - 'spec/services/hyrax/workflow/permission_query_spec.rb' + # TODO: extract CollectionAccessControls or something, so we don't have to skip this check? - 'app/models/concerns/hyrax/collection_behavior.rb' Metrics/MethodLength: diff --git a/app/services/hyrax/adapters/nesting_index_adapter.rb b/app/services/hyrax/adapters/nesting_index_adapter.rb index bc806364ac..997782fa13 100644 --- a/app/services/hyrax/adapters/nesting_index_adapter.rb +++ b/app/services/hyrax/adapters/nesting_index_adapter.rb @@ -19,14 +19,14 @@ def self.find_preservation_document_by(id:) def self.find_preservation_parent_ids_for(id:) # Not everything is guaranteed to have library_collection_ids # If it doesn't have it, what do we do? - ActiveFedora::Base.uncached do + fedora_object = ActiveFedora::Base.uncached do fedora_object = ActiveFedora::Base.find(id) + end - if fedora_object.respond_to?(:member_of_collection_ids) - fedora_object.member_of_collection_ids - else - [] - end + if fedora_object.respond_to?(:member_of_collection_ids) + fedora_object.member_of_collection_ids + else + [] end end @@ -68,16 +68,16 @@ def self.each_perservation_document_id_and_parent_ids(&block) # @param pathnames [Array] # @return Hash - the attributes written to the indexing layer def self.write_document_attributes_to_index_layer(id:, parent_ids:, ancestors:, pathnames:) - ActiveFedora::Base.uncached do - solr_doc = ActiveFedora::Base.find(id).to_solr # What is the current state of the solr document - - # Now add the details from the nesting indexor to the document - solr_doc[solr_field_name_for_storing_ancestors] = ancestors - solr_doc[solr_field_name_for_storing_parent_ids] = parent_ids - solr_doc[solr_field_name_for_storing_pathnames] = pathnames - ActiveFedora::SolrService.add(solr_doc, commit: true) - solr_doc + solr_doc = ActiveFedora::Base.uncached do + ActiveFedora::Base.find(id).to_solr # What is the current state of the solr document end + + # Now add the details from the nesting indexor to the document + solr_doc[solr_field_name_for_storing_ancestors] = ancestors + solr_doc[solr_field_name_for_storing_parent_ids] = parent_ids + solr_doc[solr_field_name_for_storing_pathnames] = pathnames + ActiveFedora::SolrService.add(solr_doc, commit: true) + solr_doc end # @api public